Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2016/functional-programming-design-and-analysis-of-algorithms/6/d/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2016 Functional programming, design and analysis of algorithms 6 d Solution by
Codex 0 2026-10-31
Suppose a Directed acyclic graph has a Hamiltonian path . Every edge forces to precede in every topological sort. Transitivity forces the entire order , so the topological sort is unique and every consecutive pair is joined by the requisite edge. No edge can point backwards in this path order, since that edge together with part of the path would form a directed cycle.
Conversely, if a topological sort has an edge from every entry to the next, those edges form a graph path through all vertices exactly once. Thus the displayed order is itself a Hamiltonian path.
The unique topological ordering criterion says that uniqueness alone already forces the consecutive-edge condition. If were absent, swapping these adjacent entries would preserve every edge constraint: only their mutual order changes, and a reverse edge is already forbidden by the original topological sort. This would produce a second order. Consequently, for a Directed acyclic graph, having a Hamiltonian path, having a unique topological sort, and having consecutive edges in a topological sort are equivalent. The source's notation is read as “appears earlier”, consistent with its explicitly directed edges.
New to topics? Read the docs here!