Professional Documents
Culture Documents
Graph
Graph
C
BFS : Algorithm
Here
= is graph
a vertex in G
. color of
. distance of
. predecessor of
[] adjacent of
BFS : Algorithm
BFS : Algorithm
BFS : Analysis
Dequeuing take 1 and for vertices
Because the procedure scans the adjacency list of
each vertex only when the vertex is dequeued,
it scans each adjacency list at most once.
the total time spent in scanning adjacency list is ()
total running time of the BFS procedure is ( + )
Depth-first search (DFS)
The strategy is to search deeper in the graph whenever possible.
This process continues until we have discovered all the vertices that
are reachable from the original source vertex.
Depth-first search (DFS)
A B C
Topological Sort
A
A C B
Topological Sort
Use
Many applications use directed acyclic graphs to
indicate precedence among events.
Example
Professor Bumstead gets dressed in the morning.
Example
Professor Bumstead gets dressed in the morning.
Topological Sort
Example
http://www.shafaetsplanet.com/planetcoding/?p=973
Strongly Connected Components
Application of DFS
What is SCS?
Strongly Connected Components
Definition
A strongly connected component of a directed
graph = (, ) is a maximal set of vertices such
that
for every pair of vertices and in , we have both
and ;
that is, vertices and are reachable from each
other.
Strongly Connected Components
Strongly Connected Components
Spanning Tree
A spanning tree of a graph is a tree that has all the
vertices of the graph connected by some edges.
A graph can have one or more number of spanning
trees.
If the graph has N vertices then the spanning tree
will have N-1 edges.
Minimum Spanning Tree
A minimum spanning tree (MST) is a spanning tree
that has the minimum weight than all other spanning
trees of the graph.
Minimum Spanning Tree: Algorithms
Prims algorithm
Kruskals algorithm
Kruskals algorithm
Choose the shortest edge (if many choose any one)
Choose next shortest edge and add it
Choose next shortest edge which would not create
any cycle and add it
Repeat until you have a minimum spanning tree
Prims Algorithm
Choose a vector
Choose shortest path from this vector
Choose nearest vertex not yet in solution
Choose next nearest vertex not yet in solution, when
there is a choice chose either
Repeat until we have a minimum spanning tree
Complexity
Kruskal = ( log )
Prim = ( + )
Dijkstras algorithm