Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between dfs and topological sort? Can topological ordering be achieved without using dfs?

I was trying to write code for detecting a cycle in a directed graph and if there is no cycle then return a topological order of the same.

While I was searching for it I came across different techniques like DFS and topological sorting to detect cycle in a directed graph.

Is there any difference between these two?

like image 900
Dhananjay Tyagi Avatar asked Oct 15 '19 06:10

Dhananjay Tyagi


Video Answer


1 Answers

Well, topological sorting is a specific order of the nodes of a directed acyclic graph, which can be achieved by depth-first search. Besides depth-first search, there are other methods to find the topological order, like the Kahn's algorighm.

like image 145
Konstantin Yovkov Avatar answered Sep 29 '22 21:09

Konstantin Yovkov