Graphs and Graph Traversals: // From Tree To Graph // Many Programs Can Be Cast As Problems On Graph
Graphs and Graph Traversals: // From Tree To Graph // Many Programs Can Be Cast As Problems On Graph
Graphs and Graph Traversals: // From Tree To Graph // Many Programs Can Be Cast As Problems On Graph
and so on…
Depth-first Search, e.g. trace it, in order
• Vertex status: undiscovered, discovered, finished
• Edge status: exploring, backtrack, checked
Depth-first search tree
• edges classified:
tree edge, back edge, descendant edge, and cross edge
Depth-first search algorithm: outline
Reaching all vertices
Depth-first search algorithm
Strongly Connected Components of a Digraph
• Strongly connected:
A directed graph is strongly connected if and only if, for each pair of vertices v
and w, there is a path from v to w.
1. color[v]=gray;
2. Preorder processing of vertex v
3. remAdj=adjVetices[v];
4. while(remAdj<>nil)
5. w=first(remAdj);
6. if(color[w]==white)
7. Explratory processing for tree edge vw.
8. int wAns=dfs(adjVetices,color, w, v,....)
9. BackTrack processing for tree edge vw using wAns(like inorder)
10. else if(color[w]==gray && w<>p)
11. Checking back edge vw
//else wv was traversed, so ignore vw.
12. remAdj=rest(remAdj)
13.Postorder processing of vertex v, including final computation of ans
14.color[v]=black;
15.return ans;
Breadth-first Search on Undirected Graph
• Simply treat the undirected graph as symmetric
digraph
in fact undirected graph is represented in adjacency list
as symmetric digraph
• Each edge is processed once in the “forward”
direction
whichever direction is encountered (explored) first is
considered “forward” for the duration of the search
Bi-connected components of an
Undirected graph
• Problem:
If any one vertex (and the edges incident upon it) are removed
from a connected graph,
is the remaining subgraph still connected?
• Biconnected graph:
A connected undirected graph G is said to be biconnected if it remains
connected after removal of any one vertex and the edges that are
incident upon that vertex.
• Biconnected component:
A biconnected component of a undirected graph is a maximal
biconnected subgraph, that is, a binconnected subgraph not contained
in any larger binconnected subgraph.
• Articulation point:
A vertex v is an articulation point for an undirected graph G if there are
distinct vertices w and x (distinct from v also) such that v is in every
path from w to x.
Bi-connected components, e.g.
• Some vertices are in more than one component
(which vertices are these?)