2
$\begingroup$

I followed an explanation of Kosaraju's and Tarjan's strongly-connected components algorithms, and they say that both have O(|V|+|E|) time complexity.

That didn't make sense to me since Kosaraju uses two DFS passes and computes the transposed graph, but Tarjan's use only one DFS.

$\endgroup$
1
  • $\begingroup$ You seem to think that Landau notation is way more useful/informative than it really is. $\endgroup$
    – Raphael
    Aug 23, 2016 at 15:12

1 Answer 1

3
$\begingroup$

they say that both have O(|V|+|E|) time complexity.

that didn't make sens for me since Kosaraju use two dfs pass and compute transpose graph, but Tarjan's use only one dfs

If you check the definition of Landau notation you will see that it does not say which function is smaller, that is (here) which algorithm is faster. It ignores constant factors.

Both algorithms have running times in $\Theta(|V| + |E|)$; that does not preclude one of them being $2^{100}$ times faster than the other for all $n \leq 2^{100}$.

$\endgroup$
2
  • $\begingroup$ "for all n < 2^100" -> What's n here, just curious? Is it |V| or |E|? $\endgroup$ Jul 10, 2021 at 4:11
  • 2
    $\begingroup$ @theprogrammer Good point. I probably intended it to be vertex count, but input size would also work for the argument. $\endgroup$
    – Raphael
    Jul 12, 2021 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.