Planar Graphs, Planarity Testing and Embedding

Planar Graphs, Planarity Testing and Embedding

Swami Sarvottamananda

Ramakrishna Mission Vivekananda University

October 2014

1 / 151 Planar Graphs, Planarity Testing and Embedding

OutlineI

1 Introduction Scope of the Lecture Definition of Planar Graphs Motivation for Planar Graphs Problem Definition

2 Characterisation of Planar Graphs Euler’s Relation for the Planar Graphs Kuratowski’s and Wagner’s Theorems Proof of Kuratowski’s theorem

3 Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Hopcroft and Tarjan’s Preliminaries Planarity Testing Algorithm

4 Planar Embedding of Graphs 2 / 151 Planar Graphs, Planarity Testing and Embedding

OutlineII Embedding Phase of Planarity Algorithm Other Embeddings

5 Conclusion Open Problems Summary References

3 / 151 Planar Graphs, Planarity Testing and Embedding Introduction

Introduction

4 / 151 Planarity Testing: Next, we give an algorithm to test planarity. Planar Embedding: Lastly we see how a given can be embedded in a plane. We also explore straight line embeddings.

Planar Graphs, Planarity Testing and Embedding Introduction Scope Scope of the lecture

Characterisation of Planar Graphs: First we introduce planar graphs, and give its characterisation and some simple properties.

5 / 151 Planar Embedding: Lastly we see how a given planar graph can be embedded in a plane. We also explore straight line embeddings.

Planar Graphs, Planarity Testing and Embedding Introduction Scope Scope of the lecture

Characterisation of Planar Graphs: First we introduce planar graphs, and give its characterisation and some simple properties. Planarity Testing: Next, we give an algorithm to test planarity.

6 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Scope Scope of the lecture

Characterisation of Planar Graphs: First we introduce planar graphs, and give its characterisation and some simple properties. Planarity Testing: Next, we give an algorithm to test planarity. Planar Embedding: Lastly we see how a given planar graph can be embedded in a plane. We also explore straight line embeddings.

7 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Definition What is a Drawing?

Definition (Drawing) Given a graph G = (V,E), a drawing maps each vertex v V to a ∈ distinct point Γ(v) in plane, and each edge e E, e = (u, v) to a ∈ simple open jordan curve Γ(u, v) with end points Γ(u), Γ(v).

Γ(a) Γ(b) a

e b Γ(e)

Γ(c) d c Γ(d)

Figure: Drawing of a graph 8 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Definition What is a Planar Graph?

Definition (Planar Graphs) Given a graph G = (V,E), G is planar if it admits a drawing such that no two distinct drawn edges intersect except at end points.

Γ(a) Γ(b) a

e b Γ(e)

Γ(c) d c Γ(d)

Figure: Planar drawing of a graph

9 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Motivation

Motivation

10 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Motivation Properties of Planar Graphs

There are number of interesting properties of planar graphs. They are sparse. There size including faces, edges and vertices is O(n). They are 4-colourable. A number of operations can be performed on them very efficiently. Since there is a topological order to the incidences. They can be efficiently stored (A data structure called SP QR-trees even allows O(1) flipping of planar embeddings).

11 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Motivation Applications of Planar Graphs

Planar graphs are extensively used in Electrical and Civil engineering. Easy to visualize. In fact, crossings reduces comprehensibility. So all good graph drawing tools use planar graphs. VLSI design, circuit needs to be on surface: lesser the crossings, better is the design. Highspeed Highways/Railroads design, crossings are always problematic. Irrigation canals, crossings simply not admissible. Determination of isomorphism of chemical structures. Most of facility location problems on maps are actually problems of planar graphs.

12 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem

Problem Definition

13 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem Problem Definition: Planarity Testing

Problem (Decision Problem) Given a graph G = (V,E), is G planar, i.e., can G be drawn in the plane without edge crossings?

14 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem Problem Definition: Planarity Embedding

Problem (Computation Problem) Given a graph G = (V,E), if G is planar, how can G be drawn in the plane such that there are no edge crossings? I.e., compute a planar representation of the graph G.

15 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem

Question: K4?

Is the following graph (K4) planar?

1

2 4

3

Figure: Graph K4

16 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem

Answer: K4 is planar

Yes, K4 is planar!

1

2 4

3

Figure: Planar K4

17 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem

Question: K5 and K3,3?

Are the following graphs (K5 and K3,3) planar? 3 1 2 5 2 3’ 1 2’

4 3 1’

Figure: Graphs K5 and K3,3

18 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem

Answer: K4 is planar

No!! They aren’t. There always will be at least one crossing.

1 3 2 5 2 3’ 1 2’ 4 3 1’

Figure: Non-planarity of K5 and K3,3

Full proofs by Euler’s celebrated theorem.

19 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem Question: Is a given graph planar?

Is the following graph planar? There are a lot of crossings O(n2).

2 1 23 22 3 21 4 20 5 19 6 18 7 17 8 16 9 15 14 10 11 12 13

Figure: A Hamiltonian Graph

20 / 151 Planar Graphs, Planarity Testing and Embedding Introduction Problem Answer: Yes

Yes, it is.

1 2 1 23 2 22 3 21 3 21 23 4 20 5 4 18 22 19 17 6 18 19 20 7 17 7 15 14 13 12 8 16 16 8 9 15 14 5 6 9 10 11 10 11 12 13

Figure: Planar embedding of the given graph

But, how to arrive at this answer? It is tough.

21 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs

Characterisation of Planar Graphs

22 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Basic Assumptions

Euler’s formula gives the necessary condition for a graph to be planar[3]. We assume that our graphs are connected and there are no self loops and no multi-edges. Disconnected graphs, 1-degree vertices, multi-edges can be easily dealt with.

23 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation for nodes, arcs and faces1

Theorem (Euler’s Relation) Given a planar graph with n vertices, m edges and f faces:

n m + f = 2 −

1 A Planar Graph : 2 3 4 n = V = 6, | | m = E = 8, and | | f = F = 4 | | 6 8 + 4 = 2 −

1The exterior is also counted as a face. The above relation also applies to simple polyhedrons with no holes. 24 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation for nodes, arcs and faces

Theorem (Euler’s Relation) Given a planar graph with n vertices, m edges and f faces:

n m + f = 2 −

A Planar Graph : n = V = 17, | | m = E = 24, and | | f = F = 9 | | 17 24 + 9 = 2 −

25 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation for nodes, arcs and faces

Proof: We prove Euler’s Relation by Mathematical Induction on vertices. If we remove one vertex v on boundary (don’t delete a cut vertex) with dv dv edges dv 1 faces, edges, then we are removing dv 1 deleted 1 vertex− − deleted faces. Thus the invariant n m + f = 2 is − maintained. Basis is an isolated vertex, n = f = 1, m = 0.

26 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation: Corollary 1

Corollary For a maximal planar graph, where each face is a triangle, m = 3n 6, and therefore, for any planar graph with at least three − vertices, we should have: m 3n 6. ≤ − P Proof: f F ef = 2m and therefore since ∈ P ef 3 ef 3f ≥ ⇒ f F ≥ ⇒ 2m 3f. ∈ ≥ Substituting in n m + f = 2 gives us − n m + 2m/3 2 − ≥ 

27 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation: Corollary 1

Example to show m 3n 6. ≤ −

Figure: Octahedron: n = 6, m = 12,m 3n 6 ≤ −

28 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation

Non-planarity of K5

Earlier we said that K5 is non-planar. Lemma

K5 is non-planar.

1

5 2

4 3

Figure: Proof: n = 5, m = 10,m> 3n 6 (= 9) − 

29 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation: Corollary 2

Corollary For a planar graph, where no face is a triangle: m 2n 4. ≤ − P Proof: f F ef = 2m and therefore since ∈ P ef 4 f F ef 4f 2m 4f. ≥ ⇒ ∈ ≥ ⇒ ≥ Substituting in n m + f = 2 gives us n m + m/2 2 − − ≥  Above relation is true for bi-partite planar graphs and graphs with no 3-cycle.

30 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation: Corollary 2

Example to show m 2n 4 for graphs without triangles. ≤ −

Figure: Cube : n = 8, m = 12,m 2n 4 ≤ −

31 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation

Non-planarity of K3,3

Earlier we said that K3,3 is non-planar. Lemma

K3,3 is non-planar.

3 2 3’ 1 2’ 1’

Figure: Proof: n = 6, m = 9,m> 2n 4 (= 8) − 

32 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation: Corollary 3

Corollary Any planar graph is 6 colourable.

x

Proof: Since m 3n 6, there exists a vertex with degree less than ≤ P− 6 (otherwise dv = 2m 2m 6n). v ⇒ ≥ By induction, if we remove this vertex, resulting graph is 6-colourable. Just give this vertex a colour other than the five colours of the neighbours.  33 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Euler’s Relation: Corollary 4

Corollary Any planar graph is 5 colourable.

34 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation 5-Colorability of planar graphs

Proof: The neighbours of a 5-degree vertex aren’t all connected. Take one such pair and do the following:

u u

x x v v

Figure: u and v are not connected

By induction, if we remove the vertex x and v, resulting graph is 5-colourable. Just give v same colour as u, and x a colour other than the 4 colours of the neighbours.  35 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Euler’s Relation Insufficiency of Euler’s Conditions

Euler’s conditions are necessary but not sufficient, for example join K5 and K3,3 by an edge.

Figure: n = 11, m = 20,m 3n 6 ≤ −

However, above graph is non-planar.

36 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems

Kurotowski’s and Wagner’s Theorem for Planar Graphs

37 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems Kuratowski’s and Wagner’s Theorems

Next we look at Kuratowski’s and Wagner’s Theorems for conditions of sufficiency. Before stating the theorems, we need to understand subdivisions and minors of a graph.

38 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems What are subdivisions and minors of a graph?

Subdivision

Minor

Figure: Subdivisions and Minors

Subdividing an edge in a planar (non-planar) graph does not make it non-planar (planar). Shrinking an edge of a planar graph to make a single vertex does not make it non-planar. 39 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems What are subdivisions and minors of a graph?

Subdivision

Minor

Figure: Subdivisions and Minors

In a way subdivision and minors are complementary. In subdivisions we add a vertex and in minors we remove a vertex. A graph is planar iff its subdivision is planar. However, if a graph is planar then its minor is planar. 40 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems Kuratowski’s Theorem

Fact Subdividing any edge means replacing the edge with a path of length 2.

Theorem (Kuratowski’s Theorem[6])

G is planar iff G contains no sub-division of K5 or K3,3.

As noted earlier, subdividing an edge in a planar graph does not make it non-planar.

41 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems Wagner’s Theorem

An alternate characterisation of planar graphs by Wagner[10].

Theorem (Wagner’s Theorem)

G is planar iff G contains no subgraph which has K5 or K3,3 as minor. See [4] for yet another characterisation by Harary and Tutte. As noted earlier, shrinking an edge of a planar graph to make a single vertex does not make it non-planar.

42 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems Necessity of Subdivisions or Minors

Can we do away with subdivisions or minors? Algorithmically, checking all minors or subdivisions is very expensive for planarity testing. Exponential if checked naively.

Checking K5 or K3,3 as subgraphs is much efficient, at least it is polynomial. Why do we need subdivisions or minors? Aren’t subgraphs sufficient?

We show a non-planar graph which does not have a K5 or K3,3 as a subgraph. So, answer is no.

43 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems Peterson’s Graph

Figure: Peterson’s Graph

A graph which doesn’t have K5 or K3,3 as a subgraph. However, it has a subdivision of K3,3 and both K5 and K3,3 as minors. 44 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems Non-planarity of Peterson’s Graph

Figure: Kuratowski’s theorem applied to the peterson’s graph

Peterson Graph has a subdivision of K3,3 . The same subgraph can be shrunk to get K3,3 as minor.

45 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Kuratowski’s and Wagner’s Theorems Non-planarity of Peterson’s Graph

Figure: Wagner’s theorem applied to the peterson’s graph

Peterson Graph has K5 as a minor.

46 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Necessity Proof of Kuratowski’s Theorem

1

5 2

4 3

Proof: (of necessity) Necessity immediately follows from non-planarity of K5 and K3,3. Any subdivison of K5 and K3,3 is also non-planar.  Necessity condition of Wagner’s theorem can also be proved easily. Shrinking edges will not change planarity. So, if we get K5 or K3,3 by shrinking edges, then initial subgraph must be non-planar to start with.

47 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem

Proof: (of sufficiency) Proof of sufficiency is a little difficult. Suppose G is non-planar. First we remove edges and vertices of a non-planar graph such that it becomes a minimal non-planar graph. I.e. removing any edge will make the resulting graph planar. We ask: How does removing an edge of a non-planar graph make it planar?

u v

Somehow we always need to join the vertices for the last edge, inside and outside of a bad cycle.

48 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

u v

Why can’t we move u or v to the other side? This cycle must be such that u and v are always on the opposite sides. There must be something which is stopping us bringing to the same side.

49 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

B B A v u

B A B

Components (minus cycle) containing u and v are conflicting with each other. Conflict only depends on placement of attachments.

50 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

All the conflicting cases can be brought under !! a finite number of cases !!.

v u u v

Both component has a pair of attachments that has uncommon attachments which are alternating. Both components have all common attachments, which number more than three. The dangling path to u and v may be empty.

51 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

These are another bunch of two cases

u v u v

One or both of the components have only one attachment, but u connects to v of non-enclosing attachments. All uncommon attachment pairs are non-alternating with at most one common attachment in between, but v connects to u in between non-alternating attachments. The dangling path to u and v may be empty. We also need to have some additional paths. 52 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

What if the components aren’t like what was shown? Then we can bring both the components on the same side and look for another cycle. We repeat until we get to the above cases. At every step we decrease at least one crossing. We show the other cases in the next slide where we can switch sides.

53 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

A few other non-conflicting cases are (for the sake of fuller argument): One or both of the components have only one attachment and uv as below. There are only two common attachments and All uncommon attachment pairs are non-alternating with at most one common attachment in between with uv as below. v u

u v u v

54 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

So, in the conflicting cases, we get:

u v u v

Either there is a pair of uncommon alternating attachments which conflict or common triplet of conflicting attachments as above (with at least one dangling path not at junction for triplet case). We get K3,3’s subdivision.

55 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

u v

Or, there are three common attachments but which make conflicting attachments as above. The dangling paths are at junction. We get K5’s subdivision.

56 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

For the other two cases mentioned, I show only single crossings of uv, multiple are similar.

u v u v

We get K3,3’s subdivision.

57 / 151 Planar Graphs, Planarity Testing and Embedding Characterisation of Planar Graphs Proof of Kuratowski’s theorem Sufficiency proof of Kuratowski’s Theorem (contd.)

Thus it can be shown that Lemma

If G is non-planar it must contain either a sub-division of K3,3 or K5.

58 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs

Planarity Testing of Graphs

59 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Testing Planarity using Kuratowski’s Theorem

Question is—How to apply Kuratowski’s theorem? A direct application is an exponential method.

60 / 151 To test for K3,3’s subdivision: n Choose 6 vertices of G. There are 6 choices. Check if 6 vertices are connected by 3 3 = 9 distinct paths × as in K3,3. No. of paths is exponential. Hard to see how both can be done in sub-exponential time.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Testing Planarity using Kuratowski’s Theorem (contd.)

To test for K5’s subdivision: n Choose 5 vertices of G. There are 5 choices. 5 Check if all 5 vertices are connected by 4 = 10 distinct paths as in K5. No. of paths is exponential.

61 / 151 Hard to see how both can be done in sub-exponential time.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Testing Planarity using Kuratowski’s Theorem (contd.)

To test for K5’s subdivision: n Choose 5 vertices of G. There are 5 choices. 5 Check if all 5 vertices are connected by 4 = 10 distinct paths as in K5. No. of paths is exponential.

To test for K3,3’s subdivision: n Choose 6 vertices of G. There are 6 choices. Check if 6 vertices are connected by 3 3 = 9 distinct paths × as in K3,3. No. of paths is exponential.

62 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Testing Planarity using Kuratowski’s Theorem (contd.)

To test for K5’s subdivision: n Choose 5 vertices of G. There are 5 choices. 5 Check if all 5 vertices are connected by 4 = 10 distinct paths as in K5. No. of paths is exponential.

To test for K3,3’s subdivision: n Choose 6 vertices of G. There are 6 choices. Check if 6 vertices are connected by 3 3 = 9 distinct paths × as in K3,3. No. of paths is exponential. Hard to see how both can be done in sub-exponential time.

63 / 151 This is easier to understand. However, worst case is still O(m!).

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Testing Planarity using Wagner’s Theorem

To test for a K5 or K3,3 minor: Choose an edge of G (m choices). Shrink it.

If 6 vertices are remaining check for K3,3.

If 5 vertices are remaining check for K5. Repeat.

64 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Testing Planarity using Wagner’s Theorem

To test for a K5 or K3,3 minor: Choose an edge of G (m choices). Shrink it.

If 6 vertices are remaining check for K3,3.

If 5 vertices are remaining check for K5. Repeat. This is easier to understand. However, worst case is still O(m!).

65 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Checking for Kuratowski’s & Wagner’s conditions Kurotowski’s and Wagner’s Conditions are not useful

Conclusion: both are obviously exponential time . How can we do it more efficiently?

66 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries

Hopcroft and Tarjan’s Planarity Testing Algorithm & Planar Embedding by Mehlhorn and Mutzel[5, 7, 8]

67 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumption

We assume the given graph is connected. We further assume the given graph is bi-connected. We get to biconnectivity in a moment.

68 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

Fact Disconnected components can be tested for planarity separately.

Figure: Disconnected

Components 69 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumptions-II

What is a biconnected or 2-connected graph?

u

Definition A graph G is biconnected iff every pair of vertices u and v are connected by at least two vertex disjoint paths except G at u and v, which are end points. v

Figure: Biconnected Graph 70 / 151 Yes! Above graph has every pair of vertices connected to each other by two vertex disjoint paths.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumptions-II

Is the following graph bi-connected?

u

G v

71 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumptions-II

Is the following graph bi-connected?

u

v

u

G v

Yes! Above graph has every pair of vertices connected to each other by two vertex disjoint paths.

72 / 151 No! Above graph is not a bi-connected graph. Every path from u to v has to pass through w, so there can only be one path. w is called cut-vertex.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumptions-II

What is a biconnected or 2-connected graph? Is the following graph bi-connected?

u

G v

73 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumptions-II

What is a biconnected or 2-connected graph? Is the following graph bi-connected?

u

w

u v

G v

No! Above graph is not a bi-connected graph. Every path from u to v has to pass through w, so there can only be one path. w is called cut-vertex. 74 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

Fact Biconnected components can be tested for planarity separately.

Figure: Biconnected Components

75 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

Fact Sometimes we may need to embed a biconnected component inside a face.

Figure: Biconnected Components 76 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

Now Let us have a general idea of the algorithm. We will take a simple example. And see how we can test planarity following Hopcroft and Tarjan’s Method.

77 / 151 FirstAfterEmanatingWeThirdThus testcomputeembed wesegment thesuitably segment firstthirddo above alledges a segmentthe DFS,segment orderingisthe is graph planar. segments planar.from segments and for is forthe mark planar. planarity. planarity. edges,cycleof back the form intreesubgraph. we the get segments. edges. original a big cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

v9 v8 v7 v10 v6

v2 v5 v1

v4 v3

Idea: Given the graph above how will we test for planarity?

78 / 151 GivenAfterEmanatingWeFirstThirdThus testcomputeembed segment thesuitably segmentthe firstthird above graph alledges segmentthe segment orderingisthe is graph planar.above segments planar.from segments for is forthe how planar. planarity. planarity. edges,cycleof will back the we form insubgraph. we test the get segments. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

v9 1v8 v8 v7 v10 v6 2v7

v2 3 v5 v2 v1 v10 v6 4 6 9 v4 v3 v3 v5 5 10 7 8 v9 v4 v1

Idea: First we do a DFS, and mark the tree edges.

79 / 151 GivenFirstEmanatingWeThirdThus testcomputeembed wesegment the segmentthe firstthirddo above graph alledges a segmentthe DFS,segment isthe is graph planar.above segments planar.from segments and for is forthe how mark planar. planarity. planarity. cycleof will back the we form intreesubgraph. test the segments. edges. fororiginal planarity? cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

v9 1v8 v8 v7 v10 v6 2v7

v2 3 v5 v2 v1 v10 v6 4 6 9 v4 v3 v3 v5 5 10 7 8 v9 v4 v1

Idea: After suitably ordering the edges, we get a big cycle.

80 / 151 GivenFirstAfterWeThirdThus testcomputeembed wesegment thesuitably segmentthe firstthirddo above graph all a segmentthe DFS,segment orderingisthe is graph planar.above segments planar. segments and for is forthe how mark planar. planarity. planarity. edges,of will back the we intreesubgraph. we test the get edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

v9 1v8 v8 v7 v10 v6 2v7

v2 3 v5 v2 v1 v10 v6 4 6 9 v4 v3 v3 v5 5 10 7 8 v9 v4 v1

1 1 S((3, 9)) 2 2 S((6, 8)) S((3, 4)) 3 3 3 9 4 6 5 8 10

Idea: Emanating edges from the cycle form segments.

81 / 151 GivenFirstAfterEmanatingWeThirdThus computetestembed wesegment thesuitably segmentthe thirddo above graph alledges a the DFS,segment orderingisthe is graph planar.above segments planar.from segments and is forthe how mark planar. planarity. edges,cycleof will back the we form intreesubgraph. we test the get segments. edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

1

2 S((3, 4)) 3

4 5

Idea: We test first segment for planarity.

82 / 151 GivenFirstAfterEmanatingWeThirdThus testcomputeembed wesegment thesuitably segmentthe firstthirddo above graph alledges a segmentthe DFS,segment orderingisthe is graph planar.above segments planar.from segments and for is forthe how mark planar. planarity. planarity. edges,cycleof will back the we form intreesubgraph. we test the get segments. edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

1

2 S((3, 4)) 3

4 5

2 S((4, 2)) S((4, 5)) 3 3

4 4 5

Idea: We compute the segments of the subgraph.

83 / 151 GivenFirstAfterEmanatingWeThirdThus testcomputeembed we thesuitably segmentthe firstthirddo above graph alledges a segmentthe DFS,segment orderingthe is graph above segments planar.from segments and for is forthe how mark planar. planarity. planarity. edges,cycleof will back the we form intreesubgraph. we test the get segments. edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

1

2 S((3, 4)) 3 1

4 2 S((3, 4)) 5 3

4 5 2 S((4, 2)) S((4, 5)) 3 3

4 4 5

Idea: First segment is planar.

84 / 151 GivenFirstAfterEmanatingWeThirdThus testcomputeembed wesegment thesuitably segmentthe firstdo above graph alledges a segmentthe DFS, orderingisthe is graph planar.above segments planar.from segments and for is thehow mark planar. planarity. edges,cycleof will back the we form intreesubgraph. we test the get segments. edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

1 S((3, 9))

2 3

9

10

Idea: We test third segment for planarity.

85 / 151 GivenFirstAfterEmanatingWeThirdThus testcomputeembed wesegment thesuitably segmentthe firstthirddo above graph alledges a segmentthe DFS,segment orderingisthe is graph planar.above segments planar.from segments and for is forthe how mark planar. planarity. planarity. edges,cycleof will back the we form intreesubgraph. we test the get segments. edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

1 S((3, 9))

2 3

9

10

2 S((9, 2)) 3

9

Idea: We compute the segments of the subgraph.

86 / 151 GivenFirstAfterEmanatingWeThus testcomputeembed wesegment thesuitably the firstthirddo above graph alledges a segmentthe DFS,segment orderingisthe graph planar.above segments from segments and for is forthe how mark planar. planarity. planarity. edges,cycleof will back the we form intreesubgraph. we test the get segments. edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

1 S((3, 9))

2 3

9

10 1 S((3, 9))

2

2 S((9, 2)) 3 3 9

9 10

Idea: Third segment is planar.

87 / 151 GivenFirstAfterEmanatingWeThirdThus testcompute wesegment thesuitably segmentthe firstthirddo above graph edges a segmentthe DFS,segment orderingis is graph planar.above segments planar.from and for is forthe how mark planar. planarity. planarity. edges,cycleof will the we form treesubgraph.we test get segments. edges. for a big planarity? cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

v9 1v8 v8 v7 v10 v6 2v7

v2 3 v5 v2 v1 v10 v6 4 6 9 v4 v3 v3 v5 5 10 7 8 v9 v4 v1 v9 1v8 v8 v7 2v7 v10

3 v6 v2 v2 v v1 10 v5 v6 4 6 9 v3 v4 v3 v5 5 10 7 8 v9 v4 v1

Idea: We embed all the segments back in the original cycle.

88 / 151 GivenFirstAfterEmanatingWeThird testcomputeembed wesegment suitably segmentthe firstthirddo graph alledges a segmentthe DFS,segment orderingisthe is planar.above segments planar.from segments and for forthe how mark planarity. planarity. edges,cycleof will back the we form intreesubgraph. we test the get segments. edges. fororiginal a big planarity? cycle. cycle.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries General Idea

v9 1v8 v8 v7 v10 v6 2v7

v2 3 v5 v2 v1 v10 v6 4 6 9 v4 v3 v3 v5 5 10 7 8 v9 v4 v1 v9 1v8 v8 v7 2v7 v10

3 v6 v2 v2 v v1 10 v5 v6 4 6 9 v3 v4 v3 v5 5 10 7 8 v9 v4 v1

Idea: Thus the above graph is planar.

89 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Planarity Testing Example : Summary

v9 1v8 v8 v7 2v7 v10 v6 3 v2 v2 v5 v10 v1 v6 4 6 9 v3 v4 v3 v5 5 10 7 8 v9 v4 v1

1 S((6, 8)) 1 S((3, 9)) 2 S((3, 4)) 3 2 3 6 3 4 8 9 5 10

Figure: Testing of planarity of a simple graph 90 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Planarity Testing Example : Summary

v9 1v8 v8 v7 2v7 v10 v6 3 v2 v2 v10 v5 v1 v6 4 6 9 v3 v4 v3 v5 5 10 7 8 v9 v4 v1

1 S((6, 8)) 1 S((3, 9)) 2 S((3, 4)) 3 2 3 6 3 4 8 9 5 10

Figure: Testing of planarity of a simple graph 91 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Planarity Testing : Key Ideas

Data structures used are very simple, sets maintained as lists or double-ended lists at most. But we do the recursive step in big-Oh of number of segments and lenght of spine. There are four salient features of the algorithm.

92 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries First Feature

First salient feature

4 5

3 1 The Edges are reordered in a certain way to embed segments outside in. 2

Figure: Outside-in Embed

Order 93 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Second Feature

Second salient feature

A(e) C(e)

Stem

AL e AR A(e0) We find a primary cycle and embed segments recursively bottom-up on e0 either side of the cycle. Spine

Figure: Bottom-up Segment Recursion

94 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Third Feature

Third salient feature

B A AB

C C D E Interlacing graph is maintained to D G E F G check conflicts between the segments. F

Figure: Interlacing graph

95 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Fourth Feature

Fourth salient feature

1 1 2 2 To embed we need to keep blocks of 3 3

4 4 conflicting segments together, which 8 8 5 5 allows us to switch side efficiently, as 7 6 7 6 well as telling us whether to order Same Reverse adjacency lists clockwise or Figure: Left or Right anticlockwise. Embedding

96 / 151 We have already used first three ideas in the example shown before.

Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Planarity Testing : Key Ideas

Four salient features of the Hopcroft and Tarjan’s Algorithm. The Edges are reordered in a certain way to embed segments outside in. We find a primary cycle and embed segments recursively bottom-up on either side of the cycle. Interlacing graph is maintained to check conflicts between the segments. To embed we need to keep blocks of conflicting segments together, which allows us to switch side efficiently, as well as telling us whether to order adjacency lists clockwise or anticlockwise.

97 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Planarity Testing : Key Ideas

Four salient features of the Hopcroft and Tarjan’s Algorithm. The Edges are reordered in a certain way to embed segments outside in. We find a primary cycle and embed segments recursively bottom-up on either side of the cycle. Interlacing graph is maintained to check conflicts between the segments. To embed we need to keep blocks of conflicting segments together, which allows us to switch side efficiently, as well as telling us whether to order adjacency lists clockwise or anticlockwise. We have already used first three ideas in the example shown before.

98 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumptions-I

We assume the following. The given graph G does not have self loops or multi-edges. G is undirected and satisfies m 3n 6. ≤ − G is connected. This also means there won’t be isolated vertices.

99 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Basic Assumptions-II

We further assume.

G

G v

v G′

G′

G is bi-connected2. If G is not, we find cut-vertices and test the planarity of each bi-connected component separately. We can embed the component in a face incident to the cut vertex3. 2So no vertex is of degree 1. 3Actually we can make any face of a planar graph the outer face. 100 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

11 10 1

9 12 14 2 8 18 13 15 We rename each vertex as its dfs 16 number for the sake of clarity. 3 7

17 6 4 5

Figure: DFS numbering 101 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

Tree edges Fronds No cross edges No forward edges

In DFS we also mark the edges as tree edges or back edges(fronds). There are no cross edges or forward edges.

102 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

C

Every cycle is simple cycle in planar embedding. S4 A cycle divides the graph into segments to be embedded. S S1 5 Each tree-edge and frond emanating

S2 S8 from the cycle is a separate segment. C exists because of biconnectivity. S3 S9 S6 S7

103 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

C(e0) e0 C(e) We embed the segments recursively. Each segment (also called branch) corresponds to a tree-edge or frond emanating from the cycle in question. Stem(e) We define stem and spine of edge e e which forms cycle C(e) with e and a frond. The segment can be embedded on one side of stem but on both sides of spine.

Spine(e) Segment of e, S(e)

104 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Hopcroft and Tarjan’s Algorithm Preliminaries Preliminaries

4 5 We wish to embed the segments outside in, so any conflicts can be 3 1 easily detected. For this we take the segments bottom up and in a particular sorted order for 2 the same node.

Embedding order

105 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage I

We are now in a position to present our algorithm. Preprocessing Step - 1 First we find out bi-connected components of the given graph G. Test planarity of each bi-connected component individually. If all are planar then G is planar. We assume for clarity that bi-connected component itself is G. We do a depth-first-search and compute all tree edges and backedges (fronds). We rename vertices with their dfs numbers.

106 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Oultline of Algorithm - Stage II

1 1 L1 2 2 8 L2 10 3 4 9 5 3 7 12 12 6 11 7 8 4 6 11 9 10 5 L1(4) = 1, L2(4) = 2

We need to sort the adjacency list of each node. So we define lowpoints — L1 and L2 for each vertex.

107 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm

Lowpoints — L1 and L2

We define lowpoints L1(u) and L2(u) for each vertex as follows. Let D(u) be set of all descendants of u and T (u) be set of all neighbours of D(u). Definition

L1(u) = min T (u) { } L2(u) = min T (u) L1(u) { − { }}

108 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm

Lowpoints Facts — L1 and L2

Fact Since G is 2-connected graph, it has no cut-vertices, so we can conclude that L1(v) < u whenever u is parent of v and u is not the root node. It follows that L2(v) u. ≤ Fact Low-points are well-defined, since every vertex has atleast 2 neighbours.

109 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Oultline of Algorithm - Stage II

Type-I Type-II Type I and Type II

There are two types of segments. One with only two attachments is called Type I and another with multiple attachments is called Type II.

110 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Oultline of Algorithm - Stage II

How to calculate Type-I and Type-II segments.

L1 L1 L1

L2

L2

v u = L u u 2 v v Type-I Type-II Type I and Type II

A branch (segment) Bu(v), where u is parent of v, with L2(v) = u is a type I branch. If L2(v) < u it is a type II branch.

111 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Oultline of Algorithm - Stage II

Fact Any number of Type-I with common attachments can be embedded inside each other. Once we get Type-II, only one can be embedded. So we need to sort the adjacency list so that Type-I segments occur before Type-II. We reorder edges of a vertex so that components are added on the tree in increasing depth of where they are attached on the DFS tree.

112 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Oultline of Algorithm - Stage II

Some segments with same starting point are shown below with their sorting keys.

2 I 3 I I II 5 I II 4 7 4 6 4 5

113 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Oultline of Algorithm - Stage II

2 I 3 I I II 5 I II 4 7 4 6 4 5

The weight of edge uv is defined as

 2v if uv is a frond with v < u   2L1(v) if u is parent of v and L2(v) = u wtu(v) = 2L1(v) + 1 if u is parent of v and L2(v) < u   2n + 1 otherwise

114 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Reordering of Edges — Example

r a b

u 4 v 3 6 5 2 1 w s x

t c

Figure: DFS tree and Lowpoints

At vertex u the branches (segments) are embedded in the order Bu(x), ua, Bu(v), ub, Bu(w), and ut Since wtu[x] = 2r < wtu[a] = 2a < wtu[v] = 2a + 1 < wtu[b] = 2b = wtu[w] < wtu[t] = 2n + 1. 115 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage II

Preprocessing Step - 2

During DFS we also calculate two lowpoint arrays L1(v)’s and L2(v)’s. We sort the adjacency lists according to the criteria of lowpoints. Use bucket sort to do it in overall linear time (keys range from 1 to 2n + 1). There is one cycle starting from root ending there, and we try to embed G branch by branch recursively.

116 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

Theorem G is planar iff each branch (segment) can be embedded on one side of its stem (defined as strongly planar). Stem is the part from L1 point to the beginning of the branch.

This enables us to check conflict only on the basis of attachments to the cycle.

117 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

Figure: Cycle of segments

The way ordering of edges is done, the cycle is always formed by the first of children till a frond is encountered to the stem. Further root has one child only (because of biconnectivity). 118 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

Ordering of Adj[u] by weights is not sufficient to guarantee that an embedding is possible without further refinement.

Figure: Conflicting Fronds and Segments

If there is a conflict then we must embed on the opposite sides of the current path from root. 119 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

A(e) C(e) We process segments bottom-up. We maintain two lists of left and right Stem attachments AL and AR as stacks. These are enough to check if there will e AR AL be conflicts. A(e0) But sometimes we need to move the segments from left to right!!! e0 We need to return AL, i.e., A(e), after Spine successful checking of planarity of S(e).

120 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

For keeping tabs on which segment conflicts which one, we compute interlacing graph.

B A AB

C C D

E D G E F G F

Interlacing graph must be bipartite. While switching we switch all the segments in a connected component.

121 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

It is easy to see that we have now an O(n3) algorithm. Computing interlacing graph itself is O(n2) in each recursive step and there are O(n) recursive steps. To do it in overall O(n) we need to compute interlacing graph implicitly, without computing all its edges. It sufficies if connected components remain connected. Even O(n) time per recursion won’t do. We need to do it in linear time of number of segments and length of spine.

122 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

ALBD ARBD

BA LBD RBD AB AB

C C

D BD D E E G G F F

BG

For that we need to treat all the conflicting segments as a block. When a block is known to conflict with another block, we combine them (union) and stitch the attachment lists (they are two ALB and ARB for each block).

123 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

ALBD ARBD

BA LBD RBD AB AB

C C

D BD D E E G G F F

BG

Now we do not switch side for individual segments, we switch a block. Switching involves linking it to other side (LB and RB for each block). Since all blocks are stitched together, all of them switch sides. For embedding we assign the side a segment ,i.e., left or right after the whole process is over.

124 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

Implicit computation of interlacing graph.

Bi 1 Bi 1 − − Bh+1 Bi

··· Bh+1 Bh

Maintenance of Interlacing graph over the tree-edge (current segment) is easy. There is an order to blocks (can be seen as stack).

125 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

We are in a position to give our main processing step. We embed the whole graph using the DFS tree T branch by branch bottom-up. First cycle will have empty stem. We first determine an ordering of adj(u) for each u so that the segments are guaranteed to permit an embedding when G is planar.

126 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

Main Processing Step Algorithm to check strong planarity of S(e) Since G is bi-connected, initially we will have a cycle C(e) found by following the first children. So we have an embedding of C(e) in the plane, with the segments to be arranged around C(e). Each segment in turn is embedded recursively bottom-up. We get its list of attachments on the stem. Then, following Hopcroft and Tarjan, we keep two linked lists of fronds, AL and AR containing the fronds and branches embedded on the left of C(e) and on the right of C(e) , respectively. AL and AR can be viewed as stacks, whose tops contain the number of the vertex currently marking the upper limit in the tree to which fronds may be embedded. 127 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm Outline of Algorithm - Stage III

Main Processing Step (contd.) We also construct the conflict graph of branches in LB and RB for each block, as IG which is a bipartite graph. Then AL and AR are unions of ALB’s and ARB’s of each block. After embedding every segment we return A(e), the attachments on the stem (i.e. by default AL). We also assign the side of each segment before returning.

128 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm

K5 Planarity Testing

How does K5 fare in our algorithm?

1 1 2 2 3 3 4 5 4 5

Figure: Testing of Planarity for K5

Last segment conflicts with both AL and AR. (Only 1-level recursion.) 129 / 151 Planar Graphs, Planarity Testing and Embedding Planarity Testing of Graphs Planarity Testing Algorithm

K3,3 Planarity Testing

How does K3,3 fare in our algorithm?

1 1 2 2

3 3 4 4 5 5 6 6

Figure: Testing of Planarity for K3,3

Last segment conflicts with both AL and AR. (Only 1-level recursion.) 130 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs

Planar Embedding of Graphs

131 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Embedding Phase of Planarity Algorithm Embedding Phase of Planarity Algorithm

Though Hopcroft and Tarjan gave the algorithm to test the planarity, they could not use it to give a planar embedding[5]. It took Mehlhorn and Mutzel another twelve years to show how Hopcroft and Tarjan’s algorithm can be used to embed a planar graph[8]. It simply means that embedding is not as obvious as it seems.

132 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Embedding Phase of Planarity Algorithm Embedding Phase of Planarity Algorithm

Theorem Let G be a biconnected planar graph. Then we can embed G in the plane in linear time[5, 8, 7].

133 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Embedding Phase of Planarity Algorithm Embedding : Key Ideas

1 1

2 2

3 3

4 4 8 8 5 5

7 6 7 6 Same Reverse

Figure: Adjacency List: Clockwise or Anti-clockwise?

Adjacency lists are arranged clockwise or anti-clockwise depending on whether the segment is embedded left of the cycle or right of the cycle.

134 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Embedding Phase of Planarity Algorithm Embedding : Key Ideas

Need to embed now, but may change sides later Will be modified later

Figure: Adjacency List: Finalising at spine

At the spine we need to order the vertices on both sides. The players are outgoing fronds, outgoing tree edges, cycle edges, and incoming fronds.

135 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Other Embeddings Other Embeddings

The embedding that we have obtained has curved edges. Sometimes we need different criteria for embedding, such as: Edges might be needed to be straight. Further, vertices might be needed on the grid. Furthermore, area might be needed to be minimized. Or we need edges made of orthogonal segments (then additionally vertices will need to be rectangular regions, for degree > 4).

136 / 151 1

3

2 4

Answer is: Yes! and we give an idea of how next.

Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Other Embeddings Straight Line embedding

Straight Line Embeddings, what are they?

1

2 4

3

Figure: Straight Line Embedding of K4

Question is: Given a planar graph G does straight line embeddings always exist? How to compute it?

137 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Other Embeddings Straight Line embedding

Straight Line Embeddings, what are they?

1

1

2 4 3

3 2 4

Figure: Straight Line Embedding of K4

Question is: Given a planar graph G does straight line embeddings always exist? How to compute it? Answer is: Yes! and we give an idea of how next. 138 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Other Embeddings Straight Line embedding: Basic Idea

v v

Stretch

Figure: Straight Line Embedding

First we triangulate the planar graph. Start with an outer edge then add vertex after vertex. We choose v such that it is connected to all consecutive nodes on the chain. Then we shift the other vertices on the chain either right or left. How much? Refer [7, 1, 9].

139 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Other Embeddings Straight Line Planar Embedding Theorem

Theorem Any planar graph with n nodes has a straight line embedding into the 2n 4 by n 2 grid such that edges are mapped into − − straight-line segments. Also such an embedding can be constructed in O(n log n) time[7, 1, 9].

140 / 151 Planar Graphs, Planarity Testing and Embedding Planar Embedding of Graphs Other Embeddings Tutte’s Theorem

Theorem (Tutte’s) If G is a 3-connected planar graph, then G has a convex embedding in the plane.

This is a stronger result that Kuratowski’s theorem.

141 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion

Conclusive Remarks

142 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion Open Problems Open Problems

Several research openings still now. Planar graphs which admit straight-line grid drawings on grids of linear area. Planar graphs which admit unit length straight-line edges. Planar graphs can be generalised to higher dimension where we have hyper-faces. If we allow crossings, then sometimes it makes sense to minimise crossings. There is a concept of book thickness of graphs. We embed the graph such that vertices are in spine and edges can be in the pages. We have to minimise number of pages.

143 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion Summary Summary

In conclusion We studied the concept of graph planarity. We gave a short proof of Kuratowski’s theorem. Next we saw how we can answer queries about planarity of graph. We looked into the planar embeddings. Now we are for the final concluding remarks.

144 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion Summary Also read

You may also read Harary’s book for basic [3]. Hopcroft and Tarjan’s paper[5] for linear planarity testing. Mehlhorn and Mutzel’s paper[8] for linear planar embeddings. S. Even, A. Lempel, and I. Cederbaum’s work[2] for a simpler embedding algorithm. Chapter 4 of Mehlhorn’s book[7] for further details

145 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion Summary Acknowledgments

Thanks to Dr Subir Ghosh, TIFR Bombay, for his suggestions.

146 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion References ReferencesI

H. de Fraysseix, J. Pach, and R. Pollack. How to draw a planar graph on a grid. Combinatorica, 10, 1990. S. Even, A. Lempel, and I. Cederbaum. An algorithm for planarity testing of graphs. In Theory of Graphs: Internat. Symposium (Rome 1966), pages 215–232, Gordon and Breach, New York, 1967. F. Harary. Graph Theory. Addison-Wesley, Reading, Mass., 1969.

147 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion References ReferencesII

F. Haray and W. T. Tutte. A dual form of kuratowski’s theorem. Bull. Amer. Math. Soc., 21(1):168, 1965. J. Hopcroft and R. E. Tarjan. Efficient planarity testing. Journal of ACM, 21(4):549–568, 1974. Kazimierz Kuratowski. Sur le probl`emedes courbes gauches en topologie. Fund. Math., 15:271–283, 1930.

148 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion References ReferencesIII

Kurt Mehlhorn. Data Structures and Algorithms 2: Graph Algorithms and NP-Completeness, volume 2 of Monographs in Theoretical Computer Science. An EATCS Series. Springer-Verlag, 1984. and Petra Mutzel. On the embedding phase of the hopcroft and tarjan planarity testing algorithm. Algorithmica, 1996. W. Schnyder. Embedding planar graphs on the grid. In First ACM-SIAM Symp. on Discrete Algorithms, pages 138–148, San Francisco, 1990.

149 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion References ReferencesIV

K. Wagner. Uber eine erweiterung eines satzes von kuratowski. Deutsche Mathematik, 2:280–285, 1937.

150 / 151 Planar Graphs, Planarity Testing and Embedding Conclusion References At Last ...

Thank You

[email protected] [email protected]

151 / 151