Data Structures and Algorithms
(CS210A)
Lecture 34
A new algorithm design paradigm: Greedy strategy
part I
1
Path to the solution of a problem
Examples
intuition/insight
Strategy
Have perseverance
Failure
Better Insight
No formula
But there is a systema

Data Structures and Algorithms
(CS210A)
Lecture 5:
More on Proof of correctness of an algorithm
Design of O() time algorithm for Local Minima in a grid
1
PROOF OF CORRECTNESS
2
What does correctness of an algorithm mean ?
For every possible valid input, t

Data Structures and Algorithms
(CS210A)
Lecture 18:
Height balanced BST
Red-black trees - II
1
Red Black Tree
Red Black tree:
a full binary search tree with each leaf as a null node
and satisfying the following properties.
Each node is colored red or blac

Data Structures and Algorithms
(CS210A)
Semester I 2014-15
Lecture 30
Binary Trees
Magical applications
1
Two interesting problems on sequences
2
Problem 1
Multi-increment
3
Problem 1
Given an initial sequence S = 0 , , 1 of numbers,
maintain a compact da

Data Structures and Algorithms
(CS210A)
Lecture 8:
Data structures:
Modeling versus Implementation
Abstract data type List and its implementation
1
Data Structure
Definition:
A collection of data elements arranged and connected in a way
that can facilit

Data Structures and Algorithms
(CS210A)
Lecture 19
Analysis of
Red Black trees
Nearly Balanced BST
1
A Red Black Tree is height balanced
A detailed proof from scratch
2
Red Black Tree
Red Black tree:
a full binary search tree with each leaf as a null node

Data Structures and Algorithms
(CS210A)
Lecture 24
BFS traversal (proof of correctness)
BFS tree
An important application of BFS traversal
1
Breadth First Search traversal
2
BFS Traversal
in Undirected Graphs
x
b
f
h
g
w
u
d
v
r
y
s
c
3
BFS traversal o

Data Structures and Algorithms
(CS210A)
Lecture 4:
Design of O() time algorithm for Maximum sum subarray
Proof of correctness of an algorithm
A new problem : Local Minima in a grid
1
Max-sum subarray problem
Given an array A storing numbers,
find its suba

Data Structures and Algorithms
(CS210A)
Lecture 31
Magical applications of Binary trees -II
1
RECAP OF LAST LECTURE
2
Intervals
S = cfw_[, ], 0 <
Question: Can we have a small set XS of intervals s.t.
every interval in S can be expressed as a union of a

Data Structures and Algorithms
(CS210A)
Lecture 12:
Queue : a new data Structure :
Finding shortest route in a grid in presence of obstacles
1
Queue: a new data structure
Data Structure Queue:
Mathematical Modeling of Queue
Implementation of Queue using

Data Structures and Algorithms
(CS210A)
Lecture 22
Graphs
Notations and terminologies
Data structures for graphs
A few algorithmic problems in graphs
1
Why Graphs ?
2
Finding shortest route between cities
Given a network of roads connecting various cit

Data Structures and Algorithms
(CS210A)
Lecture 40
Search data structure for integers : Hashing
Quick sort : some facts
1
Data structures for searching
in O(1) time
Motivating Example
Input: a given set of
1009 positive integers
Aim: Data structure for se

ESO207
Assignment 4
Summer Semester, 2017
Due Date: 10am on 14th July, 2017
Maximum Marks: 60
1. (10 points) For a graph G = (V, E), define
s(G) = max dist(u, v)
u,v
where dist(u, v) is the distance between u and v in G.
Given an undirected, connected, ac

ESO207 Assignment 2
Submit on Sunday 25/06/2017. More details about submission will be posted soon.
Question 1. [Marks 2.5% of the entire course weightage].
In this programming assignment you will implement Red-Black tree data structure. This will
include

Data Structures and Algorithms
(CS210A)
Lecture 28:
Heap : an important tree data structure
Implementing some special binary tree using an array !
Binary heap
1
Heap
Definition: a tree data structure where :
value stored in a node <? value stored in each

Data Structures and Algorithms
(CS210A)
Lecture 17:
Height balanced BST
Red-black trees
1
Terminologies
Full binary tree:
A binary tree where every internal node has exactly two children.
This node has exactly one child. So
the current tree is not a full

Data Structures and Algorithms
(CS210A)
Lecture 33
Algorithm for th order statistic of a set .
1
Problem definition
Given a set of elements and a positive integer ,
compute th smallest element from .
Applications: As wide as that of sorting.
Trivial algor

Data Structures and Algorithms
(CS210A)
Lecture 37
A new algorithm design paradigm: Greedy strategy
part IV
1
Problems solved till now
1. Job Scheduling Problem
2. Mobile Tower Problem
3. MST
Did you notice
anything commons in
their solutions ?
Ponder ove

Data Structures and Algorithms
(CS210A)
Lecture 11:
Arithmetic expression evaluation: Complete algorithm using stack
Two interesting problems
1
Quick Recap of last lecture
2
Stack: a new data structure
A special kind of list
where all operations (insertio

Data Structures and Algorithms
(CS210A)
Lecture 7:
Data structure for Range-minima problem
Compact and fast
1
Data structures
AIM:
To organize a data in the memory
so that any query can be answered efficiently.
Example:
Data: A set S of numbers
Query: Is

Data Structures and Algorithms
(CS210A)
Lecture 23
Finding a sink in a directed graph
Graph Traversal
Breadth First Search Traversal and its simple applications
1
An interesting problem
(Finding a sink)
Definition: A vertex x in a given directed graph

Data Structures and Algorithms
(CS210A)
Lecture 35
A new algorithm design paradigm: Greedy strategy
part II
1
Continuing Problem from last class
JOB Scheduling
Largest subset of non-overlapping job
2
A job scheduling problem
Formal Description
INPUT:
A s

Data Structures and Algorithms
(CS210A)
Lecture 9:
Inventing a new Data Structure with
Flexibility of lists for updates
Efficiency of arrays for search
1
Important Notice
There are basically two ways of introducing a new/innovative solution of a
problem

Data Structures and Algorithms
(CS210A)
Lecture 15:
Algorithm paradigm of Divide and Conquer :
Counting the number of Inversions
Another sorting algorithm based on Divide and Conquer :
Quick Sort
1
Divide and Conquer paradigm
An Overview
1.
2.
3.
Divide t

Data Structures and Algorithms
(CS210A)
Lecture 20
Red Black tree (Final lecture)
9 types of operations
each executed in O(log ) time !
1
Red Black tree
(Height Balanced BST)
Operations you already know
1.
2.
3.
4.
5.
Search(T,)
Insert(T,)
Delete(T,)
Min

Data Structures and Algorithms
(CS210A)
Lecture 21
Analyzing average running time of Quick Sort
1
Overview of this lecture
Main Objective:
Analyzing average time complexity of QuickSort using recurrence.
Using mathematical induction.
Solving the recurr

Data Structures and Algorithms
(CS210A)
Lecture 26
Depth First Search (DFS) Traversal
DFS Tree
Novel application: computing biconnected components of a graph
1
DFS traversal of G
DFS(v)
cfw_ Visited(v) true; DFN[v] dfn +;
For each neighbor w of v
cfw_
if

Data Structures and Algorithms
(CS210A)
Lecture 25
A data structure problem for graphs.
Depth First Search (DFS) Traversal
Novel application: computing biconnected components of a graph
1
BFS Traversal
in Undirected Graphs
x
b
f
h
g
w
u
d
v
r
y
s
c
Theore

Dynamic Programming
Version 1.0
1
1
Dynamic programming: the key idea
The solution to many problems can be written as recurrences. Often these problems are optimization problems. This
usually means that an instance of the problem can be solved by combinin

ESO207: Data Structures and Algorithms
Time: 90 min.
Quiz 1
Max. Marks: 100
Instructions.
a. Please answer all parts of a question together. You may leave blank spaces if you wish to return later to complete
parts of the question.
b. The exam is closed-bo

ESO207: Data Structures and Algorithms
Time : 60min.
Quiz 1 (Part 1) Solution
Max. Marks: 100
Instructions.
a. Answer all parts of a question together. You may leave blank spaces if you wish to return later to
complete parts of the question.
b. You may ci

CS207A: Data Structures and Algorithms (Module #3)
Assignment #1
Max marks: 55
Due on/before:17.00, 2-July-2017
23-June-2017
Note: All questions will be graded using an automated judge so please ensure that your programs follow
the input-output instructio

ESO207 Assignment 2
Submit on Friday 16/06/2017 at the start of the class.
Please write clearly.
Question 1. [Marks ].
Consider the following pseudocode which accepts input from array A containing numbers.
Initialize empty queue Q;
Initialize empty stack