Topology
Topology in Interviews
Topology is not abstraction for its own sake. Every graph connectivity algorithm computes β₀, every planarity test uses χ, every DNA-topology analysis uses knot theory.
- LeetCode Number of Islands and Number of Provinces are β₀ computations under the hood
- PCB and VLSI routing decisions reduce to planarity and minimum-genus tests
- DNA recombination and protein-knot detection rely on Fox colorings and knot polynomials
- Course Schedule and build-graph cycle detection are H₁ tests on directed complexes
Connectivity: Topological Interpretation
"Is the graph connected?" asks for β₀. "Find all connected components" computes H₀. "Does a cycle exist?" probes β₁. Topology gives a unified vocabulary for dozens of graph problems that look unrelated on the surface. Recognizing this under interview pressure separates strong candidates from the rest.
Topological facts about a graph G = (V, E): β₀(G) = number of connected components; β₁(G) = |E| − |V| + β₀ = cyclomatic number (number of independent cycles); χ(G) = |V| − |E| = β₀ − β₁. Union-Find (DSU) computes β₀ in O(α(n)) per operation - essentially constant time.
| Interview Problem | Topological Meaning | Algorithm | Complexity |
|---|---|---|---|
| Number of Islands (LC 200) | β₀ of subgraph on '1' cells | BFS / DFS / DSU | O(n·α(n)) |
| Number of Provinces (LC 547) | β₀ of undirected graph | DSU | O(n²) |
| Redundant Connection (LC 684) | Edge that creates β₁ ≥ 1 | DSU with extra_edges | O(n·α(n)) |
| Course Schedule (LC 207) | β₁ of digraph - cycle detection | Topological sort (Kahn) | O(V+E) |
| Connected Components (LC 323) | β₀ = component count | DSU | O(n·α(n)) |
Interview pattern: hear "connectivity" or "components" → reach for DSU. Hear "cycle in undirected graph" → DSU with extra_edges count. Hear "cycle in directed graph" → topological sort (Kahn's BFS). The answer frames as: β₀ = components, β₁ = independent cycles.
A graph has 7 vertices, 9 edges, and 2 connected components. What is β₁ (the cyclomatic number)?
β₁ = |E| − |V| + β₀ = 9 − 7 + 2 = 4. The graph contains 4 independent cycles.
Jordan Curve Theorem and Planar Graphs
The Jordan curve theorem seems simple: a simple closed curve in the plane divides it into exactly two regions. Yet its proof is non-trivial, requiring fundamental groups and homology. In software engineering it underlies the point-in-polygon algorithm and planar graph testing used in routing, map rendering, and VLSI layout.
Algorithmic consequences: 1. Point-in-polygon - count ray-edge crossings; odd count means inside. 2. Planar graphs satisfy Euler's formula V − E + F = 2. 3. K₅ and K₃,₃ are non-planar (Kuratowski's theorem). Non-planarity implies minimum genus ≥ 1 - the graph requires a torus to embed without crossings.
At an interview: "Whether this graph admits a drawing without edge crossings" is a planarity question. Quick test: E > 3V − 6 (or E > 2V − 4 for bipartite graphs) implies non-planar. Full O(V) testing uses the Hopcroft-Tarjan algorithm. Frame it: planarity = embeddable on S² without crossings.
The four-color theorem states every planar graph is 4-colorable. This is a theorem about S² topology. On a torus, up to 7 colors may be needed: the chromatic number bound is χ(g) = ⌊(7 + √(1+48g))/2⌋ (Heawood's formula). For g=1 (torus): χ = 7.
K₅ has V=5, E=10. Why does the edge-bound criterion declare it non-planar?
For any connected planar graph, E ≤ 3V − 6. K₅: E=10 > 9=3·5−6. The necessary condition fails, so K₅ cannot be planar.
Knot Theory and Bioinformatics
DNA inside a cell nucleus is supercoiled and knotted. Topoisomerase - an enzyme that cuts one DNA strand, passes another through, then re-ligates - literally changes the knot type. Understanding this requires knot theory. In CS, knot invariants appear in program verification, memory model analysis, and network topology proofs.
A knot is an embedding of S¹ into S³. Two knots are equivalent (ambient isotopic) if one deforms into the other without cutting. Knot invariants distinguish non-equivalent knots: Alexander polynomial Δ(t), Jones polynomial V(t), and Fox n-colorability. The unknot (trivial knot) has Δ(t) = 1 and admits only 3 colorings mod 3.
Connections to biology: 1. DNA replication requires unwinding the double helix - topoisomerase I changes the linking number 2. site-specific recombination is knot surgery 3. about 1% of proteins contain genuine knots in their backbone - AlphaFold structures are analyzed for these. The topology of the DNA configuration space determines which enzymes can unknot which configurations.
| Knot | Crossings | Δ(t) | 3-colorings | Biology |
|---|---|---|---|---|
| Unknot | 0 | 1 | 3 | Relaxed circular DNA |
| Trefoil 3₁ | 3 | 1−t+t² | 9 | DNA after recombination |
| Figure-eight 4₁ | 4 | −t+3−t⁻¹ | 3 | Protein knot type |
| Cinquefoil 5₁ | 5 | 1−t+t²−t³+t⁴ | 15 | Topoisomerase II product |
| Solomon's seal 6₂ | 6 | t²−3t+5−3t⁻¹+t⁻² | 3 | Synthetic DNA topology |
Fox 3-coloring count > 3 proves a knot is non-trivial, but the converse fails. The figure-eight knot has only 3 colorings (same as the unknot), yet it is genuinely knotted. Stronger invariants - Alexander or Jones polynomials - are needed when 3-coloring gives inconclusive results.
How does Fox 3-coloring help determine whether a knot is non-trivial?
The unknot has exactly 3 colorings. A count exceeding 3 (e.g., 9 for the trefoil) certifies non-triviality. However, 3 colorings do not guarantee the unknot - the figure-eight knot is a counterexample.
Euler Characteristic and Genus Under Pressure
"On which surface can K₅ be drawn without crossings?" - a genuine FAANG graph embedding question. The answer is the torus (genus 1), derived from the Euler characteristic formula χ = 2 − 2g and edge-count inequalities. Such questions probe depth of understanding rather than memorized algorithms.
For a graph G embedded on an orientable surface of genus g without crossing edges: V − E + F = χ = 2 − 2g. With triangular faces: 2E ≥ 3F, giving E ≤ 3(V + 2g − 2). For bipartite graphs (no triangles): E ≤ 2(V + 2g − 2). The minimum genus for which G embeds is called genus(G).
| Graph | V | E | genus | Surface | Application |
|---|---|---|---|---|---|
| K₄ | 4 | 6 | 0 | Plane S² | Tetrahedron, planar circuits |
| K₅ | 5 | 10 | 1 | Torus T² | VLSI with 1 crossing layer |
| K₃,₃ | 6 | 9 | 1 | Torus T² | 3-utilities on torus |
| K₆ | 6 | 15 | 1 | Torus T² | Complete 6-vertex graph |
| K₇ | 7 | 21 | 1 | Torus T² | 7 countries, 7 colors on torus |
| Petersen | 10 | 15 | 1 | Torus T² | Canonical non-Hamiltonian graph |
Interview cheat sheet: 1. E > 3V−6 → non-planar 2. genus(Kₙ) = ⌈(n−3)(n−4)/12⌉ 3. torus admits 7-colorings (Heawood bound) 4. treewidth(G) ≤ 3·genus(G)·Δ+1 - this connects topology to dynamic programming efficiency.
K₃,₃ is bipartite with V=6, E=9. Why does the numerical criterion show it is non-planar?
Bipartite planar graphs (which have no triangles) satisfy the tighter bound E ≤ 2V−4 = 8. Since E=9 > 8, K₃,₃ cannot be planar.
What this lesson unifies
- β₀ and β₁ provide a unified language for connectivity and cycle problems
- The Jordan curve theorem underlies point-in-polygon and planarity tests
- Fox 3-coloring distinguishes many non-trivial knots from the unknot but is incomplete
- Graph genus determines minimum VLSI layers and bounds treewidth-based DP complexity
How the full course assembles here
The final lesson assembles the course: compactness → metric spaces → fundamental group → covering spaces → homology → surface classification → Euler characteristic → manifolds → de Rham cohomology → TDA → ML applications, all appearing in concrete interview problems.
- Topology in ML and Data Science — previous lesson, supplies the Riemannian and TDA tools that resurface here
- Surface classification and Euler characteristic — supplies χ = 2 − 2g used for the genus inequalities
- Homology and Betti numbers — gives β₀ and β₁ that name the connectivity and cycle questions
Вопросы для размышления
- Which interview problem now reads differently through the lens of β₀ or β₁?
- Number of Islands is β₀, Redundant Connection detects β₁ ≥ 1, Course Schedule is cycle detection in a digraph - which production graph problems sit in the same family?
- Where would the genus inequality E ≤ 3(V + 2g − 2) help estimate VLSI layer count or treewidth bounds?