I'm trying to design an algorithm to determine whether a directed graph has a unique topological ordering. Anyone know how to write pseudo-code for this?
Recall the procedure of the topological sort, which is in short:
n
which is a sink in the graphn
, and n
from the graphIf at any iteration, at step 2 you have a choice to pick 1 from 2 or more nodes, the topological sort is not unique. If at any point, you are stuck before exhausting the graph - there is no topological sort at all.