Algorithms Ch22A
Algorithms Ch22A
Algorithms Ch22A
404
Analysis of Algorithms
Prof. Karen Daniels
Spring, 2007
A B A B
C C
D F D E F
E
Introductory Graph Concepts:
Motivation
A B A B
C C
D E F D E F
0 1 1 0 0 0
0 1 1 0 0 0
1 0 1 0 1 1
0 0 1 0 1 1
1 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 1 0 0
0 1 0 1 0 1
0 1 0 1 0 0
0 1 0 0 1 0
0 0 0 0 1 0
Introductory Graph Concepts:
Paths, Cycles
A B
C
D E F
A B
C
D E F
A B
C
D E F
A B
C
D E F
A B
C
D E F
A B
C
D E F
Depth-First Search (DFS)
&
Breadth-First Search (BFS)
DFS PseudoCode
Vertex Color Changes
Edge Classification
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example: (continued)
DFS of Directed Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example:
DFS of Undirected Graph
Example: (continued)
DFS of Undirected Graph
A
A B Tree Edge
Back
C
Edge Tree Edge
F
B Tree Edge
E Tree Edge
D E F
C Cross Edge
Tree Edge
D
Breadth-First Search (BFS)
BFS PseudoCode
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example:
BFS of Directed Graph
Example: (continued)
BFS of Directed Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example:
BFS of Undirected Graph
Example: (continued)
BFS of Undirected Graph
Depth-First Search (DFS)
&
Breadth-First Search (BFS)
ri
O (| V | + | E |)
Topological Sort
Definition: DAG
Topological Sort
Example
Example
Topological Sort
Topological Sort