learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 Exercises with Hints, Worked Algorithms and Complete Solutions

By Mohammed Islam Hadjoudj

Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

Planarity Test

Can it be drawn without a single crossing?

Decides whether a graph can be drawn without crossings by drawing it again face by face, and shows the K5 or K3,3 that blocks it when it cannot

Time: O(n²)
Space: O(n + m)
Use Case: Circuit layout, map drawing, graph drawing, teaching Euler's formula
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Planarity Test (Kuratowski, DMP)

A graph is planar if it can be drawn in the plane with no two edges crossing. The question is about the graph, not the drawing: a planar graph may be drawn with crossings, as in this page's example, and the test must find a drawing without them or prove that none exists. Kuratowski's theorem (1930) gives the certificate for the second case: a graph is non-planar exactly when it contains a subdivision of K5 (five vertices all joined) or K3,3 (three houses joined to three utilities).

How it works

This visualizer uses the algorithm of Demoucron, Malgrange and Pertuiset (1964) on each biconnected block. It draws a cycle first, which splits the plane into an inside and an outside face. Then it repeats: the fragments are the parts not drawn yet, and a fragment fits in a face when all its attachment vertices are on that face's border. If a fragment fits in no face, the graph is not planar. Otherwise a path of a fragment that fits in only one face (or of any fragment) is drawn through that face, splitting it in two. For a non-planar graph, removing edges while the rest stays non-planar leaves the Kuratowski subgraph, shown with its branch vertices. The method runs in O(n²). Linear-time tests exist, but they are much harder to follow.

Applications

Planarity matters wherever crossings cost: printed circuit boards and chip layouts (wires on one layer cannot cross), drawing maps, diagrams and networks legibly, and laying out pipes or roads. Planar graphs have special properties that algorithms exploit: Euler's formula n − m + f = 2, at most 3n − 6 edges, four colours always suffice, and many hard problems become easier. The test is also a step in graph drawing software, which first checks planarity and then computes a crossing-free layout.

Pseudocode

On each biconnected block: start with a cycle, then keep drawing paths of the most constrained fragment into faces.

DMP(B):                            // B a biconnected block
    H = a cycle of B, faces = {inside, outside}
    loop:
        F = fragments: undrawn edges with both ends in H,
            and pieces of undrawn vertices with their edges
        if F is empty: return PLANAR
        for each fragment f: faces(f) = faces holding all its attachments
        if some faces(f) is empty: return NOT PLANAR
        f = a fragment with one face, else any fragment
        P = a path in f between two attachments
        draw P through the face, which splits in two

Preferring a fragment that fits in only one face is what makes the method correct. When every fragment fits in two or more faces, any choice can be completed if the graph is planar, as Demoucron, Malgrange and Pertuiset proved.

Worked example, step by step

The test on the example loaded on this page: an octahedron drawn on a hexagon, with six crossings.

Example graph: Six vertices A to F on a hexagon. Each is joined to its two neighbours and to the two vertices two places along, 12 edges, every vertex of degree 4.

  1. A first cycle. The triangle A, B, C is drawn. It has an inside face and an outside face.
  2. A free choice. The undrawn vertices form one fragment attached at A, B and C, which fits in both faces. The path A, F, B is drawn into face 1.
  3. Forced paths. Now a fragment fits in only one face, so the path A, E, D, B goes there. Then the single edges F–D and E–F are drawn into faces that hold both their ends.
  4. Last edges. E–C and C–D are drawn the same way. All 8 faces are now triangles, and no fragment is left.
  5. Euler check. The drawing has 8 faces: n − m + f = 6 − 12 + 8 = 2, as Euler's formula requires for a connected planar graph.

Planar, with 8 faces: the octahedron can be drawn without crossings, as a triangle inside a triangle with the edges between them. The crossings were only in the drawing.

Complexity, and where it comes from

Time: O(n²) · Space: O(n + m)

A planar graph has at most 3n − 6 edges, so checking m > 3n − 6 rejects dense graphs at once. Each round of DMP finds the fragments and their faces in O(n + m) = O(n) and draws at least one edge, for O(n) rounds and O(n²) in all. Extracting a Kuratowski subgraph by deleting edges repeats the test for each edge, which is fine for small graphs.

When to use Planarity Test (Kuratowski, DMP), and when not to

Planarity can be tested in linear time, but the linear methods are harder to follow.

AlternativePrefer it whenCost
Hopcroft-Tarjan (1974)The first linear-time test, path addition with a DFS. Long and intricate to implement.O(n)
Boyer-Myrvold (2004)Linear time, builds the embedding or a Kuratowski subgraph directly. Used in the Boost Graph Library and SageMath.O(n)
Left-right planarity (de Fraysseix)Linear time, considered the simplest of the fast tests. Used in NetworkX's check_planarity.O(n)

Common pitfalls

  • Judging by the drawing. Crossings in a drawing prove nothing: the example has six and is planar. Only a test, or a crossing-free drawing, decides.
  • Using only the edge bound. m ≤ 3n − 6 is necessary, not sufficient. K3,3 has 9 edges and 6 vertices, well under 12, and is still not planar.
  • Looking for K5 and K3,3 themselves. Kuratowski's theorem is about subdivisions, paths in place of edges. The Petersen graph contains no K5 or K3,3 as a subgraph, but it contains a subdivision of K3,3.

Frequently asked questions

What is a planar graph?
A graph that can be drawn in the plane so that edges meet only at their endpoints. Such a drawing is called a plane embedding.
What does Kuratowski's theorem say?
A graph is planar exactly when it contains no subdivision of K5 or K3,3. Wagner's theorem says the same with minors instead of subdivisions.
What is Euler's formula?
For a connected planar drawing with n vertices, m edges and f faces, n − m + f = 2. From it follows m ≤ 3n − 6 for n ≥ 3.
Why does planarity matter for colouring?
The four colour theorem says every planar graph can be coloured with four colours. Planarity is also what makes many hard problems easier, through separators and duality.

Related algorithms: Graph Coloring, Biconnected Components, Chordality Check, Articulation Points, Maximal Clique

An example graph: you can change it, or start blank.

Zoom Controls

52%
Nodes: 6
Edges: 12