admin管理员组文章数量:1405156
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.
本文标签: data structuresWhat is the correct order after topological sortStack Overflow
版权声明:本文标题:data structures - What is the correct order after topological sort? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744879544a2630123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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