450 likes | 598 Views
Testing planarity part 1. Thomas van Dijk. Preface. Appendix of Planar Graph Drawing Quite hard to read So we’ll try to explain it, not just tell you about it. Preface. “ There are a number of efficient algorithms for planarity testing, which are unfortunately all difficult to implement.”
E N D
Testing planaritypart 1 Thomas van Dijk
Preface • Appendix of Planar Graph Drawing • Quite hard to read • So we’ll try to explain it, not just tell you about it
Preface • “There are a number of efficient algorithms for planarity testing, which are unfortunately all difficult to implement.” • (www.mathworld.com)
Preface • “There are a number of efficient algorithms for planarity testing, which are unfortunately all difficult to implement.” • (www.mathworld.com) • Implementation in Mathematica was actually bugged until version 4.2.1 (!) • (Also mathworld.com)
What is planarity testing? • Whether a graph can be drawn on the plane without edge crossings • Equivalently, whether a “planar embedding” of the graph exists
Embedding • Adjacency-list representation of the graph • Order in the list defines clockwise order of the edges
Embedding • Adjacency-list representation of the graph • Order in the list defines clockwise order of the edges 1 2 2 4 3 4 3 1 3 4 1 2 4 3 1 2
Embedding • Adjacency-list representation of the graph • Order in the list defines clockwise order of the edges 2 4 3 1 1 2 2 4 3 4 3 1 3 4 1 2 4 3 1 2 3 3 4 1 2 4 3 1 2 1 4 2
Overview • “Vertex addition algorithm” • First presented by Lempel et al (’67) • Improved to linear time byBooth and Lüker (’76) • We present this second algorithm
Main idea • Start with one vertex • Add vertices and their edges one by one • make sure we don’t break planarity • If you can’t add the next vertex, graph is not planar • add the vertices in an order such that if we fail, we that know that using any other order wouldn’t have worked either
We need to know about • Some general observations • st-Numbering • Bush forms / PQ-Trees
O(m) is O(n) for planar graphs • Remember from Euler’s Theorem we have thatm ≤ 3n-6for simple plane graphs • Algorithm can just reject graphs with too many edges. • So from now on, O(m) is O(n)
Biconnected components • Definition:A graph G is biconnected ifffor every two distinct vertices there exist two internally disjoint paths between them • Also iff G contains no cut-vertices • i.e.: cannot be made unconnected by removing a single vertex
Biconnected components • Theorem:A graph is planar iffall its biconnected components are planar • Proof:Induction on the number of biconnected components
Biconnected components • If the graph is planar, clearly its biconnected components are planar • A graph is planar iff its connected components are planar • A connected graph with no biconnected components is a tree; trees are planar
Biconnected components • If a graph has one biconnected component, then all vertices not in it are in trees. So the graph is planar iff the biconnected component is planar
Biconnected components • Induction step: • The next biconnected component is connected to the rest of the graph by a cut-vertex v.
Biconnected components • Induction step: • The next biconnected component is connected to the rest of the graph by a cut-vertex v. • Since the biconnected component itself is planar, an embedding with v on the exterior exists. (As Hans showed us.)
Biconnected components • The biconnected components of a graph can be found in linear time • (If you are interested, an exercise in Cormen et al explains it) • So from now on, we can assume graphs are biconnected.
st-Numbering • From the ‘main idea’ slide:“Add the vertices in an order such that if we fail, we that know using any other order wouldn’t have worked either”
8 1 st-Numbering • Special nodes: source s (“1”) and sink t (“n”) • “1” and “n” adjacent
8 1 st-Numbering • Special nodes: source s (“1”) and sink t (“n”) • “1” and “n” adjacent • j V-{s,t}: i, k Adj(j)st(i)<st(j)<st(k)
8 1 7 2 st-Numbering • Special nodes: source s (“1”) and sink t (“n”) • “1” and “n” adjacent • j V-{s,t}: i, k Adj(j)st(i)<st(j)<st(k) • So 2 must be next to 1and n-1 must be next to n
8 5 1 7 2 3 6 4 st-Numbering • Special nodes: source s (“1”) and sink t (“n”) • “1” and “n” adjacent • j V-{s,t}: i, k Adj(j)st(i)<st(j)<st(k) • So 2 must be next to 1and n-1 must be next to n
2 1 4 6 3 5 11 12 9 7 10 8 5 4 1 3 2 Some st-numbering examples
st-Numbering • Theorem:Every biconnected graph has an st-numbering • Proof:We give an algorithm and show that it works if the graph is biconnected • Our graph is biconnected, so anst-numbering exists.
Finding an st-numbering • First step, standard DFS. • Can visit children in any order • Calculate and store per vertex: • Parent • “Depth first search number:” DFN • Low-point: the lowest DFN among nodes that can be reached by a path using any amount of tree edges followed by 1 back edge
G DFS
DFN 6 G 5 4 3 2 DFS 1
DFN LOW 6 3 G 5 3 4 1 3 1 2 1 DFS 1 1
Finding an st-numbering • Push the vertices onto a stack and pop them off • Four rules for what to push and pop • Assign increasing numbers to the vertices when they are popped off for the last time • Example follows
Initial setup • The node with DFN 2 is called the ‘source’ • The node with DFN 1 is called the ‘sink’ • Stack with sourceon top of sink • Source and sinkare “old” b a d c ac e f
Rule “2” • There is a “new” tree edge: follow it and take the path that leads to its low point • Push the vertices on the path ontothe stack • Mark all as old. b a abc d c e f
No matches for vertex a • There are now no rule matches for a. • Pop it off the stack and give it the next available number • This node is ready b 1 d c bc e f
Rule “3” • There is a “new” back edge into this node: from the other end, go back up tree edges to an “old” vertex • Push the vertices onthe path ontothe stack • Mark all as old bfedc b 1 d c e f
No matches for vertex b • So the vertex is ready and gets its number fedc 2 1 d c e f
No matches for vertex f • So the vertex is ready and gets its number edc 2 1 d c e 3
Et cetera… 2 1 5 6 4 3
Correctness • All vertices are numbered • The numbering is indeed an st-numbering
Algorithm recap • For linear complexity, we need thatO(m) = O(n). • For correctness, we need that the graph is biconnected
After the break … • Ron will tell you about: • bush forms and PQ-trees • how it all fits together into a planarity testing algorithm
Any questions? • http://www.planarity.net/