The task is to perform a topological sort of a graph with 7→5, 7→6, 5→2, 5→4, 6→3, 6→4, 2→1, 3→1, and 1→0:
The correct answer is given as [7, 6, 5, 4, 3, 2, 1, 0]
.
But why does 4
come first instead of 3
even though the degree of 3
becomes 0 first?
Could someone please explain it?
The task is to perform a topological sort of a graph with 7→5, 7→6, 5→2, 5→4, 6→3, 6→4, 2→1, 3→1, and 1→0:
The correct answer is given as [7, 6, 5, 4, 3, 2, 1, 0]
.
But why does 4
come first instead of 3
even though the degree of 3
becomes 0 first?
Could someone please explain it?
1 Answer
Reset to default 2There is no order between 3
and 4
; topological order is a partial order (outside "linear" graphs).
Where there are unordered nodes, more than one linearisation is valid.
Any given one may be the result of a specific procedure; I take your the degree of 3
becomes 0 first to refer to one.
4
can be anywhere later than5
and6
(and7
by extension).3
can be anywhere later than6
(and again, 7 by extension). There is no dependency between3
and4
, so they can appear in any order relative to each other. – Alexander Commented Mar 9 at 3:25