Presentation is loading. Please wait.

Presentation is loading. Please wait.

Articulation Points 2 of 2 (Algorithm)

Similar presentations


Presentation on theme: "Articulation Points 2 of 2 (Algorithm)"— Presentation transcript:

1 Articulation Points 2 of 2 (Algorithm)
COMP261 Lecture 9 Articulation Points 2 of 2 (Algorithm)

2 Outline Recursive Articulation Points Finding
Iterative Articulation Points Finding

3 Articulation Points Key ideas of algorithm:
Record count number of nodes as you search From each recursive search of a subtree, return the minimum count number that the subtree nodes can "reach back" to. Compare the "reach back" of each subtree to count number of this node, if smaller then there is an alternative path

4 Articulation points: Recursive
Initialise: for each node: node.count ← , articulationPoints ← { } start.count ← 0, numSubtrees ← 0 for each neighbour of start if neighbour.count =  then recArtPts(neighbour, 1, start) numSubtrees ++ if numSubtrees > 1 then add start to articulationPoints recArtPts(node, count, fromNode): node.count ← count, reachBack ← count, for each neighbour of node other than fromNode if neighbour.count <  then reachBack = min(neighbour.count, reachBack) else childReach = recArtPts(neighbour, count +1, node) if childReach >= count then add node to articulationPoints reachBack = min(childReach, reachBack ) return reachBack B C D A E M P L J Back edge No back edge from the child Q

5 Recursive algorithm count: 2 parent: F reachBack: 2 Recursion may be annoying Can we do it iteratively? G 2 count: 3 parent: G reachBack: 3 J H 3 count: 4 parent: J reachBack: 4 \ 3 L 4 3 count: 5 parent: L reachBack: 5 N \ 3 M M 5 6 3 P count: 7 parent: M reachBack: 7 count: 6 parent: M reachBack: 6 Q 7 6 \ 4 \ 3

6 Removing Recursion The process is essentially a DFS
Use stack for DFS (last-in-first-out) iterDFS: initialise an empty stack Pick a root, push root onto stack repeat until stack is empty: pop node from stack process node for each unvisited neighbour of node push neighbour onto stack

7 Articulation points: Iterative
Initialise: for each node: node.count ←  articulationPoints ← { } start.count ← 0, numSubtrees ← 0 for each neighbour of start if neighbour.count =  then recArtPts(neighbour, 1, start) numSubtrees ++ if numSubtrees > 1 then add start to articulationPoints iterArtPts(neighbour, 1, start)

8 Articulation points: Iterative
iterArtPts(node, count, root): stack ← an empty stack, push <node, count, root> onto stack repeat until stack is empty: pop <node, count, fromNode> from stack node.count ← count, node.reachBack ← count updateReachBack(node) for each neighbour of node other than fromNode push <neighbour, count+1, node> onto stack Require calculation of neighbour.reachBack Process node How to update?

9 Articulation points: Iterative
iterArtPts(node, count, root): stack ← an empty stack, push <node, count, root> onto stack repeat until stack is empty: pop <node, count, fromNode> from stack node.count ← count, node.reachBack ← count for each neighbour of node other than fromNode if neighbour.count <  then node.reachBack = min(neighbour.count, node.reachBack) else childReach = recArtPts(neighbour, count+1, node) if childReach >= count then add node to articulationPoints node.reachBack = min(childReach, node.reachBack) push <neighbour, count+1, node> onto stack Process node Still need recursion for childReach

10 Articulation points: Iterative
Without recursion, a node needs to be processed When first reached: initialise count, reachBack, … After processing each neighbour: update reachBack After the last neighbour: transfer reachBack to fromNode However, the simple stack only processes a node when first reached Need more sophisticated stack

11 Articulation points: Iterative
A more sophisticated stack while stack is not empty peek at element on top of stack perform next action of element Initialise count/reachBack Process neighbour (may push onto the stack) Transfer reachBack to fromNode if all actions have been done then remove element from stack

12 Stack for Iterative Articulation Points
Stack elements contain node: graph node to be processed count reachBack children: unvisited neighbours fromNode When peek at an element First time: initialise count, reachBack and children Process a child: poll a child; if visited, update reachBack; otherwise push onto stack Last time: determine if fromNode is articulation point, update fromNode’s reachBack

13 Articulation points: Iterative
Initialise: for each node: node.count ←  articulationPoints ← { } start.count ← 0, numSubtrees ← 0 for each neighbour of start if neighbour.count =  then iterArtPts(neighbour, 1, start) numSubtrees ++ if numSubtrees > 1 then add start to articulationPoints

14 Articulation Points with Stack
iterArtPts (firstNode, count, root): push <firstNode, count, root> onto stack repeat until stack is empty: peek at <node, count, fromNode> from stack if node.count =  then node.count ← count, node.reachBack ← count, node.children ← new queue for each neighbour of node if neighbour ≠ fromNode then add neighbour to node.children else if node.children not empty then child ← node.children.dequeue() if child.count < ∞ then node.reachBack ← min(node.reachBack, child.count) else push 〈child, count+1, node〉 onto stack else if node ≠ firstNode then if node.reachBack ≥ fromNode.count then add fromNode to articulationPoints fromNode.reachBack = min (fromNode.reachBack, node.reachBack) remove <node, count, fromNode> from stack First time Children to process Last time


Download ppt "Articulation Points 2 of 2 (Algorithm)"

Similar presentations


Ads by Google