I'm implementing topological sort on directed graph using DFS without modifying graph. So I chose a time measuring method.
IMO, it's enough just having boolean flags indicates started or finished for all vertices.
- If I visit started, but unfinished vertex, it's a back-edge and a cycle.
- If I save vertex in order it finishes, it's topologically sorted list.
But all the texts on the internet just says to measure time number, so I'm not sure my opinion is right. (I'm self learner and not good at algorithms) Did I miss something? Or is that just a conceptual description?