Applications of DFS
1
The White-Gray-Black DFS
DFS is useful for simple ood-lll since its easy to code. However, there are more complicated
algorithm that uses DFS. In particular, these algorithms make use of the DFS tree. To explain what
a DFS tree is, w
#include <stdio.h>
#include <stdlib.h>
/* A binary tree
and a pointer
struct node
cfw_
int data;
struct node*
struct node*
;
node has data, pointer to left child
to right child */
left;
right;
int printPathsRecur(struct node* node, int count)
cfw_
int lef
CMP SC 3050: In-class Practice 3
Consider the graph G:
3
4
6
2
5
1
1. Give the adjacency matrix representation of G.
2. Give the adjacency list representation of G.
3. Give the distances and the BFS tree generated by running the Breadth
First Search algor
CMP SC 3050 Homework 3
Due: 11:59:59 pm, 03/15/2016
The third homework for CMP SC 3050 is a programming assignment. There are 40
points possible for this assignment and will contribute towards 4% of your total
grade. The first part of the homework specifi
CMP SC 3050: Course organization
Rohit Chadha
Chadha
CMP SC 3050: Course organization
1/9
CMP SC 3050: Advanced algorithm design
What is this course about?
I
I
I
Design of efficient algorithms
Design and use of data structures in algorithms
Mathematical a
CMP SC 3050: Review Session I
Problem 2.3-7: Assume that S is stored in an array
First sort the array S using merge-sort
For each element S[i], we can do a binary search to find if x S[i]
is also in S. Note that we only have to search for x S[i] in the
Greedy Algorithms
Used for optimization problems
Make locally optimal choice
Don't always yield optimal solution
Initially R is the set of all activities
A is empty (* A will store all the activities that will be scheduled *)
while R is not empty
choose
Greedy Graph
Dijkstras Algorithm
All weights must be positive
Is a greedy algorithm
Computes the shortest paths from s to all vertices
For every vertex u S, u.d is length of shortest path from s.
For vertices v Q, v.d is the length of shortest path, all o
CMP SC 3050 Homework 4
Due: 11:59:59 pm, 11/11/2016
The third homework for CMP SC 3050 is a programming assignment. There are 40
points possible for this assignment and will contribute towards 4% of your total
grade. The first part of the homework specifi
CMP_SC 3050 Homework 1
Due: 11:59:59 pm, 9/8/2016
The first homework of the semester is a programming assignment. The homework is
out of 30 points and will contribute to 3% of your total grade. The first part of the
homework specifies the exact problems t
CMP SC 3050 Homework 3
Due: 11:59:59 pm, 10/18/2016
The third homework for CMP SC 3050 is a programming assignment. There are 40
points possible for this assignment and will contribute towards 4% of your total
grade. The first part of the homework specifi
CMP SC 3050: Connected Components of Directed
Graphs
Rohit Chadha
Chadha
CMP SC 3050: Connected Components of Directed Graphs
1 / 23
Strongly connected component of a digraph
u is said to strongly connected to v if there is a directed path from u
to v and
CMP SC 3050: More greedy algorithms in graphs:
minimum spanning trees
CMP SC 3050: More greedy algorithms in graphs: minimum spanning trees
1 / 30
Minimum Spanning Tree
Input Connected undirected graph G = (V , E ) with edge
costs/weights w (i, j)
Goal Fi
CMP SC 3050: In-class Practice 2
Consider the one-dimensional array:
A= 2
0
1
0
15 12
10
1. Draw the nearly complete binary tree corresponding to array A above.
2. The pseudocode for heap-sorting an array A of size n is
HeapSort(A, n)
1 Build-Max-Heap(A,
Machine Problem 2
Due Monday 2/27/2012 by noon
A bridge of an undirected connected graph G = (V,E) is an edge whose removal disconnects G.
In this program you will read a file specifying an undirected connected graph as a list of edges
and output the numb
Machine Problem 3
Due Monday 3/19/2012 by noon
Given an undirected edge-weighted graph G= (V,E), a linear ordering of G is a permutation of the
vertices of G. In other words, each vertex v is assigned a position p(v) between 1 and |V|, and no two
vertices
Machine Problem 5
Due Monday 4/30/2012 by noon
In this program you will read a file specifying a directed edge-weighted graph G as a list of edges. Each
edge uv is listed on one line as u v w, where w is its weight. For simplicity, all weights are integer
Machine Problem 1
Due Monday 2/13/2012 by noon
In this program you will read a file specifying an undirected graph as a list of edges and output
either a YES or NO depending on whether the graph is a tree or not. The input file simply lists
the edges in a
CMP SC 3050: A greedy algorithm in graphs
CMP SC 3050: A greedy algorithm in graphs
1 / 13
Shortest Paths
Input: A directed graph G = (V , E ) with weights w (i, j) for each
edge (i, j) E , a source vertex s and destination vertex t
Output: The shortest w
CMP SC 3050: Asymptotic growth of functions
Rohit Chadha
Chadha
CMP SC 3050: Asymptotic growth of functions
1 / 15
Asymptotic analysis
Running times are functions of sizes of input
Our focus is on how the running time grows as input size grows
Such kind o
CMP SC 3050: Elementary Data structures
Rohit Chadha
Chadha
CMP SC 3050: Elementary Data structures
1 / 21
Data structures
A data structure is a structure to organize data
I
By data, we mean input, output and intermediate data used to
compute the output
E
CMP SC 3050:Introduction to dynamic programming
CMP SC 3050:Introduction to dynamic programming
1 / 26
Example: Rod-cutting
Input A rod of length n and table of prices pi for i = 1, 2, . . . , n
Goal Cut the steel rod into pieces such that the revenue obt
CMP SC 3050: Connected Components of Directed
Graphs
Rohit Chadha
Chadha
CMP SC 3050: Connected Components of Directed Graphs
1 / 23
Strongly connected component of a digraph
u is said to strongly connected to v if there is a directed path from u
to v and
CMP SC 3050: Introduction to Greedy Algorithms
Rohit Chadha
Chadha
CMP SC 3050: Introduction to Greedy Algorithms
1 / 29
Used for optimization problems (i.e. when we have to optimize some
objective)
Idea:
When we have a choice to make, make the one that l