Purpose: Decide whether a graph is planar — drawable in the plane with no edge crossings — in time. The first linear-time planarity test (1974).

Preliminaries

By Euler’s formula , a simple planar graph satisfies (and if bipartite/triangle-free). So the first line of any planarity test is:

if (E > 3 * V - 6) return false;   // not planar, and now everything is O(V)

This is why the complexity is stated in alone.

By Kuratowski’s theorem, a graph is planar iff it contains no subdivision of or . Testing that directly is hopeless; the algorithms below take structural routes instead.

The path addition method

  1. Reduce to a biconnected graph (planarity is testable per biconnected component, see biconnected components).
  2. Find a cycle ; the rest of the graph decomposes into bridges (pieces attached to ).
  3. Embed , then add the remaining pieces one path at a time, deciding for each whether it goes inside or outside the cycle.
  4. The inside/outside choices interact: two pieces “conflict” if they interleave on the cycle and cannot both go on the same side. Build a conflict graph and test it for 2-colourability — this is exactly 2-SAT / bipartiteness.
  5. Hopcroft and Tarjan use a DFS with careful ordering so that the conflicts can be resolved with a stack in linear time, rather than building the conflict graph explicitly.

Complexity

  • Time:
  • Space:
  • Reputation: notoriously difficult to implement correctly — the original paper’s presentation is famously terse

The alternatives

MethodTimeDifficultyProduces an embedding?
checktrivialrejects only
Hopcroft-Tarjan (path addition)very hardyes
Lempel-Even-Cederbaum + PQ-treeshardyes
Boyer-Myrvold (edge addition)moderateyes, plus Kuratowski subgraph
de Fraysseix-Rosenstiehl (left-right)moderateyes

If you need this

Use Boyer-Myrvold or the left-right criterion. Both are substantially easier than Hopcroft-Tarjan, and Boyer-Myrvold additionally extracts an explicit / subdivision when the graph is not planar — useful for constructive problems.

Where planarity shows up in contests

Rarely as an explicit test. More often you are told the graph is planar and expected to exploit it:

  • planar graphs are 4-colourable (and 5-colourable constructively in linear time);
  • they have edges, so becomes ;
  • they have separators (Lipton-Tarjan), enabling divide and conquer;
  • max flow in planar graphs has algorithms via duality — a min cut in the primal is a shortest cycle in the dual.

Variants / Use Cases

  • Boyer-Myrvold — the implementable modern choice
  • Tarjan’s biconnected components — the required preprocessing
  • Planar separator theorem — the algorithmic payoff of planarity
  • Graph drawing — Tutte’s spring embedding, Schnyder woods for straight-line grid drawings