Time complexity for generating all possible topological sorts of a graph

Viewed 303

I was going through the solution to find and print all the topological sorts of a directed acyclic graph using backtracking with kahn sorting.

Complete solution is here: https://www.geeksforgeeks.org/all-topological-sorts-of-a-directed-acyclic-graph/

According to me, the time complexity of this solution would be O(V!) where V = total vertex of graphs. Worst case would be V disconnected vertices. In that case, in each ith recursion we would be traversing (i-1) vertices with in-degree as 0. Total number of topological sorts = O(V!) in that case.

Can you please help me with the time complexity of the solution? Would it be O(V!)?

0 Answers
Related