Guest
Sign in to keep your graphs and progress.

Practice book
Graph Theory Through Problems300 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.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
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
Select an algorithm and generate steps to begin visualization
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).
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.
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.
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 twoPreferring 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.
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.
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.
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.
Planarity can be tested in linear time, but the linear methods are harder to follow.
| Alternative | Prefer it when | Cost |
|---|---|---|
| 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) |
Related algorithms: Graph Coloring, Biconnected Components, Chordality Check, Articulation Points, Maximal Clique