Lecture Notes on 19 Apr 2013
For the graph given in class
Depth First Search (DFS)
Event Stack
A A
B AB
F ABF
H ABFH
Pop H ABF
Pop F AB
Pop B A
C AC
Pop C A
D AD
G ADG
I ADGI
Pop I ADG
Pop G AD
Pop D A
E AE
Pop E A
Pop A -
DFS starting at A: ABFHCDGIE
Breadth First Search (BFS):
Event Queue
A
B B
C BC
D BCD
E BCDE
Deq B CDE
F CDEF
Deq C DEF
Deq D EF
G EFG
Deq E FG
Def F G
H GH
Deq G H
I HI
Deq H I
Deg I -
BFS starting at A: ABCDEFGHI
Topological Sort in a Directed Graph
Step 0: Create an empty sequence list.
Step 1: Find a vertex that has no successors.
Step 2: Delete this vertex from the graph and insert this vertex
to the beginning of the sequence list.
Step 3: Repeat Steps 1 and 2 till there are no more vertices.
The sequence list has the vertices in topological order.
Minimum Cost Spanning Tree - Kruskal's Algorithm
Step 1: Create a list of edges.
Step 2: Sort that list in order of increasing weight (cost).
Step 3: Keep adding the edges from the sorted list to the
minimum cost spanning tree as long as the edge does not form
a cycle.
When there are no more edges to add, you have the minimum cost
spanning tree.