7 Finding Bridge in a Graph
What is a bridge ? A C D B F G E
Why we need to find bridge(s)? A graph with a lot of bridge is weakly connected.
Articulation Point A C D B E We will not cover how to find articulation point(s) now, but it is similar to bridge’s
Trivial Algorithm
We can find bridge(s) in a graph using modified DFS algorithm.
AC D B F G E A B D E C G F A E C G
We want to gather more information from DFS, so we add ordering number and parent’s id.
AC D B F G E A B D E C G F A E C G NodeABCDEFG Order Parent-ABCCEF 1/- 2/A 3/B 4/C 5/C 6/E 7/F A is C’s ancestor, because the order number is smaller C is A’s descendant, because the order number is bigger
Notice that whenever we find an ancestor node, we actually found a cycle. We can count the cycle’s size by tracing up, using parent’s info that we stored. A B D E C G F A E C G NodeABCDEFG Order Parent-ABCCEF 1/- 2/A 3/B 4/C 5/C 6/E 7/F
Observe: Cycle AC D B F G E
DFS
NodeABCDEFG Order Parent-ABCCEF Low# Initially, low is set to order number When found an ancestor node, return its low # A node always choose smaller low # of its children A B D E C G F A E C G 1/-/1 2/A/2 3/B/3 4/C/4 5/C/5 6/E/6 7/F /B/1 2/A/1 7/F/5 6/E/5
Every pink and red edges on DFS Tree corresponds to an edge on original graph A B DE C G F A E C G 1/-/1 2/A/1 3/B/1 4/C/4 5/C/5 6/E/5 7/F/ AC D B F G E There are 3 nodes which has same order and pre number Corresponding edges of these nodes are bridges Root doesn’t have corresponding edge So we only have 2 bridges in this graph
Running Time