Compute any topological sort using a standard algorithm, then check its consecutive entries in the adjacency matrix:If all checks pass, the returned ordering is a Hamiltonian path. If a check fails but a Hamiltonian path existed, part (d) would force the computed topological sort to equal the unique path order, whose consecutive edges all exist. This contradiction proves the negative answer correct.
DAGHamiltonianPath(A):
order = TopologicalSort(A)
for j = 1,...,n-1:
if not A[order[j],order[j+1]]:
return "no Hamiltonian path"
return orderA standard topological sort scans all matrix rows and therefore takes time with this input representation; the subsequent edge checks take . The answer is consequently time, with auxiliary storage beyond the input matrix. An bound for an adjacency list must not be substituted for the stipulated adjacency matrix bound.
Articles by others on the same topic
There are currently no matching articles.