Content deleted Content added
m Dating maintenance tags: {{Cleanup HTML}} |
Changed <tt> to <code> (the recommended markup in Help:Wikitext and removed HTML cleanup tag |
||
Line 1:
{{Infobox algorithm
|class=
Line 22 ⟶ 21:
=== Stack invariant ===
Nodes are placed on a [[Stack (data structure)|stack]] in the order in which they are visited. When the depth-first search recursively visits a node <
At the end of the call that visits <
=== Bookkeeping ===
Each node <
== The algorithm in pseudocode ==
Line 79 ⟶ 78:
'''end function'''
The <
The outermost loop searches each node that has not yet been visited, ensuring that nodes which are not reachable from the first node are still eventually traversed. The function <
When each node finishes recursing, if its lowlink is still set to its index, then it is the root node of a strongly connected component, formed by all of the nodes above it on the stack. The algorithm pops the stack up to and including the current node, and presents all of these nodes as a strongly connected component.
Note that <
== Complexity ==
''Time Complexity'': The Tarjan procedure is called once for each node; the forall statement considers each edge at most once. The algorithm's running time is therefore linear in the number of edges and nodes in G, i.e. <math>O(|V|+|E|)</math>.
In order to achieve this complexity, the test for whether <
This may be done, for example, by storing a flag on each node that indicates whether it is on the stack, and performing this test by examining the flag.
''Space Complexity'': The Tarjan procedure requires two words of supplementary data per vertex for the <
==Additional remarks==
|