Presentation is loading. Please wait.

Presentation is loading. Please wait.

Biconnected Graph Articulation Points

Similar presentations


Presentation on theme: "Biconnected Graph Articulation Points"— Presentation transcript:

1 Biconnected Graph Articulation Points

2 Biconnected Graph A biconnected graph has at least 2 distinct paths (no common edges or vertices) between all vertex pairs Any graph that is not biconnected has one or more articulation points Vertices, that, if removed, will separate the graph Any graph that has no articulation points is biconnected Thus we can determine that a graph is biconnected if we look for, but do not find any articulation points

3 Finding articulation points
DFS pre-order traversal Two arrays

4 DFS pre-order traversal
public Biconnected(Graph G) { pre = new int[G.V()]; for (int v = 0; v < G.V(); v++) pre[v] = -1; if (pre[v] == -1) dfs(G, v); } private void dfs(Graph G, int v) { pre[v] = cnt++; for (int w : G.adj(v)) { if (pre[w] == -1) { dfs(G, w); }

5 DFS pre-order traversal
M J B H D C K G I E L B F A M J D C G K I H E private void dfs(Graph G, int v) { pre[v] = cnt++; for (int w : G.adj(v)) { if (pre[w] == -1) { dfs(G, w); }

6 DFS pre-order traversal
M J B H D C K G I E L B F A M J D C G K I H E private void dfs(Graph G, int v) { pre[v] = cnt++; for (int w : G.adj(v)) { if (pre[w] == -1) { dfs(G, w); } 1-based counting pre: A L M J B H K G I D E C F 1 2 3 4 5 6 7 8 9 10 11 12 13

7 Finding articulation points
M J B H D C K G I E Finding articulation points DFS pre-order traversal Two arrays – pre[] pre-order traversal order pre[M]==3 means M is the 3rd node we visit Node close to root should have smaller traversal order number pre: A L M J B H K G I D E C F 1 2 3 4 5 6 7 8 9 10 11 12 13

8 Finding articulation points
M J B H D C K G I E Finding articulation points Spanning tree edges Back edges private void dfs(Graph G, int v) { pre[v] = cnt++; for (int w : G.adj(v)) { if (pre[w] == -1) { // <v, w> is a spanning tree edge dfs(G, w); } else { // <v, w> is a back edge since we have already visited node w }

9 Finding articulation points
M J B H D C K G I E Finding articulation points DFS pre-order traversal Two arrays – low[] Low[] records the earliest ancestor a node and its children could reach For spanning tree edge (v, w), low[w] >= pre[v] means v is a articulation point Since the earliest ancestor of w is v, it could not be earlier than v E.g. (B, D) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 12 13 low

10 Finding articulation points
M J B H D C K G I E Low[v] records the earliest ancestor node v and its children could reach Min of three cases 1) Basic case: low[v] = prev[v] Node v could reach itself Def: Low[] records the earliest ancestor a node and its children could reach v

11 Finding articulation points
M J B H D C K G I E Low[v] records the earliest ancestor node v and its children could reach Min of three cases 2) v has back edges (v, w): Compare pre[w] to low[v] fix v, for all w E.g. node G choose B among {K, H, B} When we search from node v, we know pre[w] since we already visited the node w could not be the parent of v w v A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 12 13 low

12 Finding articulation points
M J B H D C K G I E Low[v] records the earliest ancestor node v and its children could reach Min of three cases 3) v has spanning tree edges (v, w): Compare low[w] to low[v] E.g. node M choose A since its children B could reach A What if children of B could have smaller low value? When we search from node v, we DO NOT know low[w] until we return from the next recursive call v A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 12 13 low w

13 Finding articulation points
M J B H D C K G I E Min of three cases 1) Basic case: low[v] = prev[v] 2) v has back edges (v, w): compare pre[w] to low[v], e.g. node G 3) v has spanning tree edges (v, w): compare low[w] to low[v], e.g. node M For the case 3), we have to make the comparison after recursive call, since then we have information of low[w] Decide the low[] value of leaf node at the beginning Update low[] in the path E.g. Only when we know low[C]=1, we could finally decide that low[B]=1, then low[M]=1, low[L]=1

14 private void dfs(Graph G, int u, int v) { int children = 0; pre[v] = cnt++; low[v] = pre[v]; for (int w : G.adj(v)) { if (pre[w] == -1) { children++; dfs(G, v, w); low[v] = Math.min(low[v], low[w]); if (low[w] >= pre[v] && u != v) articulation[v] = true; } else if (w != u) low[v] = Math.min(low[v], pre[w]); } if (u == v && children > 1) Case 1: basic public Biconnected(Graph G) { low = new int[G.V()]; pre = new int[G.V()]; articulation = new boolean[G.V()]; for (int v = 0; v < G.V(); v++) low[v] = -1; pre[v] = -1; if (pre[v] == -1) dfs(G, v, v); } Case 3: spanning tree edge The condition Case 2: back edge Special case for root node

15 A L F M J B H D C K G I E A L M J B H K G I D E C F pre 1 2 3 4 low
(1, 1) A L F M J B H D C K G I E (2, 2) A L M J B H K G I D E C F pre 1 2 3 4 low (3, 3) (3, 2) (5, 5) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 low (4, 2) (6, 6) (6, 5) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 low (10, 10) (7, 7) (11, 5) (7, 5) (8, 5) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 low (9, 9)

16 A L F M J B H D C K G I E A L M J B H K G I D E C F pre 1 2 3 4 5 6 7
8 9 10 11 low (1, 1) A L F M J B H D C K G I E (13, 13) (2, 2) (2, 1) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 low (3, 3) (3, 2) (3, 1) (5, 5) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 12 low (4, 2) (5, 1) (12, 1) (6, 6) (6, 5) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 12 low (10, 10) (7, 7) (10, 5) (11, 5) (7, 5) (8, 5) A L M J B H K G I D E C F pre 1 2 3 4 5 6 7 8 9 10 11 12 13 low (9, 9)


Download ppt "Biconnected Graph Articulation Points"

Similar presentations


Ads by Google