Does Tarjan's SCC algorithm give a topological sort of the SCC?

后端 未结 3 735

I\'ve been studying SCC and algorithms about them, and I\'ve seen that people almost always mention that Kosaraju\'s algorithm finds the SCC and also gives them ordered in a (re

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 01:55

    Yes, it does. Tarjan's SCC algorithm works by performing a DFS on a graph and keeping track of the roots of the SCCs on a stack. One method of finding a topological sort is performing a DFS on a graph and keeping track of the exit order. The exit order of these nodes in Tarjan's SCC algorithm provide a topological sort.

    Donald Knuth even mentions it in an interview when talking about Tarjan's SCC algorithm, which he says is one of his favorite:

    The data structures that he devised for this problem fit together in an amazingly beautiful way, so that the quantities you need to look at while exploring a directed graph are always magically at your fingertips. And his algorithm also does topological sorting as a byproduct.

提交回复
热议问题