Back to Graph Theory Series

Linear-Time Planarity Testing

October 11, 2026Wasil Zafar28 min read

Can a graph be drawn without edge crossings? Modern algorithms answer in linear time and produce the embedding when the answer is yes.

Contents

  1. From Euler to Linear Time
  2. Drawing vs Embedding
  3. Euler Bounds
  4. Obstructions
  5. Testing Workflow
  6. Embedding Output
  7. Implementation
  8. Worked Examples
  9. Applications
  10. Pitfalls
  11. Complexity and Choice

From Euler’s Formula to Linear-Time Testing

Euler supplied the first numerical invariant of a crossing-free drawing. Kuratowski later identified the two unavoidable topological obstructions, and Hopcroft and Tarjan showed that planarity can be decided in linear time. The modern problem is richer than a yes/no test: when a graph is planar, we want an embedding; when it is not, we often want a compact witness.

The conceptual progression

EulerFaces, edges, and vertices obey a rigid equation in the plane.
KuratowskiEvery nonplanar graph hides a subdivided $K_5$ or $K_{3,3}$.
AlgorithmsDFS constraints construct an embedding or expose an obstruction in $O(V+E)$.

A Crossed Drawing Is Not a Nonplanarity Proof

A graph is planar if it has some drawing in the plane where edges meet only at common endpoints. A plane graph is a planar graph together with one particular crossing-free embedding.

Intuition A tangled route map may be badly drawn even when the roads can be rearranged cleanly. Planarity asks whether an untangled arrangement exists, not whether the first sketch has crossings.
A crossed drawing and planar embedding of the same K4 graph On the left, K4 is drawn as a square with both diagonals, producing a crossing that is not a vertex. On the right, the same graph is drawn as a triangle with the fourth vertex inside and no crossings. Crossed drawing of K₄ Planar embedding of the same K₄ the center crossing is not a vertex ABCD ABCD same six edges, different geometry
$K_4$ looks crossed in the square layout but is planar. Redrawing one vertex inside a triangle removes every crossing.

Topology, not aesthetics

Edge curves may bend as much as needed. Their exact coordinates do not matter; only which vertices are joined and whether edge interiors intersect.

Euler’s Formula Gives Fast Rejection Bounds

For a connected plane graph, with $n$ vertices, $m$ edges, and $f$ faces including the outer face:

$$n-m+f=2$$

In a simple planar graph with $n\ge3$, each face boundary has length at least $3$, while every edge borders two face-sides. Thus $3f\le2m$. Combining the inequalities with Euler’s formula gives:

$$m\le3n-6$$

If the graph is bipartite, it has no odd cycle, so every face has length at least $4$ and the stronger bound is:

$$m\le2n-4$$
CheckIf it failsIf it passes
Simple bound $m\le3n-6$Definitely nonplanarStill unknown
Bipartite bound $m\le2n-4$Definitely nonplanarStill unknown
Full planarity testReturns an obstructionReturns an embedding

A bound is a one-way filter

Too many edges proves nonplanarity. Few enough edges proves nothing. Subdividing obstruction edges adds vertices without removing the topological obstruction, so a nonplanar graph can be very sparse.

The Two Shapes Behind Every Nonplanar Graph

$K_5$ connects every pair of five vertices. $K_{3,3}$ connects each of three left vertices to each of three right vertices. Neither is planar.

The K5 and K3,3 Kuratowski obstructions The complete graph on five vertices appears on the left. The complete bipartite graph with three vertices on each side appears on the right. Every planar obstruction contains a subdivision of one of these two graphs. K₅: every pair is adjacent K₃,₃: every left–right pair 12345 abcxyz 5 vertices · 10 edges6 vertices · 9 edges
Kuratowski’s theorem says a graph is nonplanar exactly when it contains a subdivision of $K_5$ or $K_{3,3}$. The crossings in these sketches are unavoidable, not merely poor layout choices.

A subdivision replaces an edge with a path by inserting degree-2 vertices. Suppressing those degree-2 vertices recovers the original obstruction. This explains why edge-density bounds are incomplete: subdivisions make a graph larger and sparser without making it planar.

Kuratowski view

Look for a subgraph that is a subdivision of $K_5$ or $K_{3,3}$.

Wagner view

A graph is planar exactly when it has neither $K_5$ nor $K_{3,3}$ as a minor.

What a Linear-Time Tester Actually Does

Production algorithms differ in their data structures, but the shared logic is to expose how non-tree edges must attach around a DFS skeleton and check whether all left/right placement constraints can be satisfied.

Planarity-Test Workflow
flowchart TD
    G[Normalize graph and split components] --> B[Process biconnected blocks]
    B --> D[Build DFS tree and lowpoint data]
    D --> C[Propagate embedding constraints]
    C --> Q{Constraints consistent?}
    Q -->|Yes| P[Return planar rotation system]
    Q -->|No| K[Return Kuratowski witness]
  1. Normalize: handle isolated vertices, components, self-loops, and parallel edges according to the library’s contract.
  2. Decompose: planarity can be checked block by block because articulation vertices can join planar pieces.
  3. Search: a DFS tree orders ancestor paths; lowpoint information summarizes how subtrees reconnect upward.
  4. Constrain: back-edge attachments must be placed consistently on the two sides of partial embeddings.
  5. Certify: produce a rotation system or extract a $K_5/K_{3,3}$ subdivision.

A certificate is more useful than a boolean

A planar embedding can drive a drawing or face traversal. A Kuratowski witness explains exactly which part of a nonplanar input makes success impossible.

The Real Positive Output: A Rotation System

A combinatorial embedding records the cyclic order of incident edges around every vertex. This rotation system determines how edges thread through the plane without committing to screen coordinates.

OutputWhat it containsWhat it enables
BooleanPlanar or nonplanarFiltering only
Rotation systemCyclic neighbor order at each vertexFace traversal, dual graph, drawing
Kuratowski witnessObstruction subgraph with subdivision pathsDebugging and explanation
CoordinatesA geometric realizationRendering; usually produced by a later layout step

For simple planar graphs, Fáry’s theorem guarantees that some crossing-free straight-line drawing exists. The planarity tester usually supplies the topology first; a planar drawing algorithm then chooses coordinates and visual spacing.

Embedding is not layout

A rotation system answers “which edge comes next around this vertex?” It does not decide edge lengths, angles, labels, or aesthetic balance.

Implement the Safe Prechecks; Reuse the Full Tester

Density checks are simple and valuable, but their return type should communicate definite rejection, not planarity. The snippets assume a simple graph.

def rejected_by_density(vertices, edges, bipartite=False):
    if vertices < 3:
        return False
    limit = 2 * vertices - 4 if bipartite else 3 * vertices - 6
    return edges > limit

print(rejected_by_density(5, 10))        # True: rejects K5
print(rejected_by_density(6, 9))         # False: K3,3 remains unknown
print(rejected_by_density(6, 9, True))   # True: bipartite bound rejects it
bool rejectedByDensity(long long vertices, long long edges,
                       bool bipartite = false) {
    if (vertices < 3) return false;
    long long limit = bipartite
        ? 2 * vertices - 4
        : 3 * vertices - 6;
    return edges > limit;
}

// false means “unknown,” never “proved planar”
bool k33General = rejectedByDensity(6, 9);       // false
bool k33Bipartite = rejectedByDensity(6, 9, true); // true
static boolean rejectedByDensity(long vertices, long edges,
                                 boolean bipartite) {
    if (vertices < 3) return false;
    long limit = bipartite
        ? 2 * vertices - 4
        : 3 * vertices - 6;
    return edges > limit;
}

// false means “unknown,” never “proved planar”
boolean k33General = rejectedByDensity(6, 9, false); // false
boolean k33Bipartite = rejectedByDensity(6, 9, true); // true

Integration checklist

  • Confirm whether the tester accepts multigraphs, self-loops, and disconnected inputs.
  • Preserve an edge-ID map if simplified edges must be restored later.
  • Request an embedding when faces, a dual graph, or coordinates will follow.
  • Validate that every original edge appears exactly twice in the directed-edge face traversal.
  • Request or verify a nonplanarity witness when diagnostics matter.

Worked Examples: What Each Check Can Prove

Graph$n$$m$Density resultActual status
$K_4$$4$$6$Meets $3n-6=6$Planar
$K_5$$5$$10$Fails $m\le9$Nonplanar immediately
$K_{3,3}$, general bound$6$$9$Passes $m\le12$Still nonplanar
$K_{3,3}$, bipartite bound$6$$9$Fails $m\le8$Nonplanar immediately
Every $K_{3,3}$ edge subdivided once$15$$18$Passes even $m\le26$Nonplanar by Kuratowski

The final row is the important one: adding degree-2 vertices dilutes density while preserving the obstruction. No edge-count inequality can replace the structural test.

Reason about a subdivision

Subdivide every edge of $K_5$ once. The new graph has $15$ vertices and $20$ edges. Does passing both density bounds make it planar?

Answer: no. Suppressing the ten new degree-2 vertices recovers $K_5$, so Kuratowski’s obstruction is still present.

Where Planarity Testing Pays Off

Routing

Single-Layer Feasibility

A topological routing model can reveal whether crossings are unavoidable before geometric spacing and manufacturing rules are added.

Graph Drawing

Embedding Before Layout

A rotation system provides the face structure needed by planar straight-line and orthogonal drawing algorithms.

Maps and Networks

Topological Validation

Check whether an abstract adjacency model can be represented without unintended intersections.

Algorithm Selection

Unlock Planar Algorithms

Verified planar structure enables separators, duality, and specialized algorithms with stronger guarantees.

Topology is only the first routing layer

A planar abstract graph may still be difficult to route with fixed terminal positions, obstacles, minimum spacing, or restricted bend counts. Those are geometric constraints beyond planarity.

Common Misreadings and Boundary Cases

MistakeWhy it failsBetter interpretation
“My sketch crosses, so the graph is nonplanar.”Another embedding may remove crossings.Test the abstract graph.
“The edge bound passes, so it is planar.”The bounds are necessary, not sufficient.Continue to a full test.
Treating a geometric crossing as a vertexThat changes the graph’s adjacency.Crossings are not vertices unless explicitly modeled.
Using simple-graph bounds on loops or parallel edgesFace-length assumptions change.Simplify first or use the tester’s multigraph rules.
Expecting coordinates from an embeddingA rotation system is combinatorial.Run a planar layout stage afterward.
Confusing planarity with minimum crossingsTesting zero crossings is easier than optimizing a positive number.Use a crossing-number or crossing-minimization method.

Complexity and Choosing the Right Tool

Hopcroft–Tarjan, Boyer–Myrvold, and other established approaches run in $O(n+m)$ time. The asymptotic result is elegant; the implementation details are subtle enough that a mature library is usually safer than a fresh production implementation.

GoalGood starting pointOutput
Cheap rejectionEuler density boundsDefinitely nonplanar or unknown
Decide planarityLinear-time planarity testerBoolean
Draw a planar graphTester + embedding + planar layoutCoordinates and routes
Explain nonplanarityTester with witness extraction$K_5/K_{3,3}$ subdivision
Minimize crossingsCrossing-minimization methodA drawing with few crossings
Maintain planarity under updatesDynamic planarity data structureUpdate-aware embedding state

Mental model to keep

Density bounds can reject, obstructions can explain, and a full tester decides. A successful result is best understood as a cyclic edge order around every vertex—not merely a prettier version of the input sketch.