# 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.

## Presentation on theme: "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."— Presentation transcript:

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.”  (www.mathworld.com)www.mathworld.com

Preface “There are a number of efficient algorithms for planarity testing, which are unfortunately all difficult to implement.”  (www.mathworld.com)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 4 2 3 2 4 3 4 3 1 3 1 21 2 4

Embedding Adjacency-list representation of the graph Order in the list defines clockwise order of the edges 1 4 2 3 2 4 3 4 3 1 3 1 21 2 4 1 2 3 4 2 4 3 3 4 1 1 4 2 1 2 3

Overview “Vertex addition algorithm” First presented by Lempel et al (’67) Improved to linear time by Booth 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 that m ≤ 3n-6 for 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 iff for 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 iff all 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”

st-Numbering Special nodes: source s (“1”) and sink t (“n”) “1” and “n” adjacent 1 8

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) { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/11/3162093/slides/slide_22.jpg", "name": "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-Numbering Special nodes: source s (“1”) and sink t (“n”) “1” and “n” adjacent j V-{s,t}: i, k Adj(j) st(i) { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/11/3162093/slides/slide_23.jpg", "name": "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-Numbering Special nodes: source s (“1”) and sink t (“n”) “1” and “n” adjacent j V-{s,t}: i, k Adj(j) st(i) { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/11/3162093/slides/slide_24.jpg", "name": "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)

Some st-numbering examples 12 1 11 2 10 3 9 4 8 5 7 6 3 1 5 2 4

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 an st-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 G

1 2 3 4 5 6 DFN DFS G

1 2 3 4 5 6 DFN 1 1 1 1 3 3 LOW DFS G

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 source on top of sink Source and sink are “old” c f d b e a acac

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 onto the stack Mark all as old. c f d b e a abcabc

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 c f d b e 1 bcbc

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 on the path onto the stack Mark all as old c f d b e 1 bfedcbfedc

No matches for vertex b So the vertex is ready and gets its number c f d 2 e 1 fedcfedc

No matches for vertex f So the vertex is ready and gets its number c 3 d 2 e 1 edcedc

Et cetera… 6 3 5 2 4 1

Correctness All vertices are numbered The numbering is indeed an st-numbering

Algorithm recap For linear complexity, we need that O(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/

Download ppt "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."

Similar presentations