Testing planarity part 1

44
Testing planarity part 1 Thomas van Dijk

description

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.” - PowerPoint PPT Presentation

Transcript of Testing planarity part 1

Page 1: Testing planarity part 1

Testing planaritypart 1

Thomas van Dijk

Page 2: Testing planarity part 1

Preface

Appendix of Planar Graph Drawing Quite hard to read So we’ll try to explain it, not just tell you

about it

Page 3: Testing planarity part 1

Preface

“There are a number of efficient algorithms for planarity testing, which are unfortunately all difficult to implement.” (www.mathworld.com)

Page 4: Testing planarity part 1

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)

Page 5: Testing planarity part 1

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

Page 6: Testing planarity part 1

Embedding

Adjacency-list representation of the graph Order in the list defines clockwise order of

the edges

Page 7: Testing planarity part 1

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

Page 8: Testing planarity part 1

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 21 2 3

Page 9: Testing planarity part 1

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

Page 10: Testing planarity part 1

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 planaradd the vertices in an order such that if we

fail, we that know that using any other order wouldn’t have worked either

Page 11: Testing planarity part 1

We need to know about

Some general observations st-Numbering Bush forms / PQ-Trees

Page 12: Testing planarity part 1

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)

Page 13: Testing planarity part 1

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

Page 14: Testing planarity part 1

Biconnected components

Theorem:A graph is planar iffall its biconnected components are planar

Proof:Induction on the number of biconnected components

Page 15: Testing planarity part 1

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

Page 16: Testing planarity part 1

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

Page 17: Testing planarity part 1

Biconnected components Induction step: The next biconnected component is

connected to the rest of the graph by a cut-vertex v.

Page 18: Testing planarity part 1

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

Page 19: Testing planarity part 1

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.

Page 20: Testing planarity part 1

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”

Page 21: Testing planarity part 1

st-Numbering

Special nodes: source s (“1”) and sink t (“n”)

“1” and “n” adjacent

1

8

Page 22: Testing planarity part 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) 1

8

Page 23: Testing planarity part 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)

So 2 must be next to 1and n-1 must be next to n

2 71

8

Page 24: Testing planarity part 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)

So 2 must be next to 1and n-1 must be next to n

4 6

2

5

71

3

8

Page 25: Testing planarity part 1

Some st-numbering examples

12

1

11

2

10

3

9

4

8

5

7

6

31

5

2

4

Page 26: Testing planarity part 1

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.

Page 27: Testing planarity part 1

Finding an st-numbering

First step, standard DFS. Can visit children in any order Calculate and store per vertex:

Parent“Depth first search number:” DFNLow-point: the lowest DFN among nodes that

can be reached by a path using any amount of tree edges followed by 1 back edge

Page 28: Testing planarity part 1

G

Page 29: Testing planarity part 1

DFS

G

Page 30: Testing planarity part 1

1

2

3

4

5

6 DFN

DFS

G

Page 31: Testing planarity part 1

1

2

3

4

5

6 DFN

1

1

1

1

3

3LOW

DFS

G

Page 32: Testing planarity part 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

Page 33: Testing planarity part 1

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”

c

f

d

b

e

a

ac

Page 34: Testing planarity part 1

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.

c

f

d

b

e

a

abc

Page 35: Testing planarity part 1

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

bc

Page 36: Testing planarity part 1

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 c

f

d

b

e

1 bfedc

Page 37: Testing planarity part 1

No matches for vertex b

So the vertex is ready and gets its number

c

f

d

2

e

1fedc

Page 38: Testing planarity part 1

No matches for vertex f

So the vertex is ready and gets its number

c

3

d

2

e

1

edc

Page 39: Testing planarity part 1

Et cetera…

6

3

5

2

4

1

Page 40: Testing planarity part 1

Correctness

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

Page 41: Testing planarity part 1

Algorithm recap

For linear complexity, we need thatO(m) = O(n).

For correctness, we need that the graph is biconnected

Page 42: Testing planarity part 1

After the break …

Ron will tell you about:bush forms and PQ-treeshow it all fits together into a planarity testing

algorithm

Page 43: Testing planarity part 1

Any questions?

Page 44: Testing planarity part 1

Any questions?

http://www.planarity.net/