You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/graph/strongly-connected-components.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -234,8 +234,7 @@ We consider the minimal value of $t_{in}$ of the unclaimed vertices we can reach
234
234
We will call the propagated value $t_{low}$.
235
235
236
236
More formally, we define $t_{low}[v]$ to be the lowest value of $t_{in}$ a vertex in the subtree of $v$ can reach through a direct edge.
237
-
238
-
We therefore can detect whether a vertex $v$ is a root or not by checking if $t_{low}[v] < $t_{in}[v]$.
237
+
We therefore can detect whether a vertex $v$ is a root or not by checking if $t_{low}[v] < t_{in}[v]$.
239
238
240
239
Lastly, to claim the vertices, there are many ways to do it, such as another graph traversal algorithm, but it's also possible to use a simple data structure to keep track of the unclaimed vertices.
241
240
To determine the data structure from first principles, let's go through the methods it must implement, which are only two:
@@ -258,12 +257,12 @@ We can now see that this can be implemented with a stack:
258
257
259
258
This finally lets us implement the algorithm.
260
259
261
-
The runtinme complexity of the sequence of `dfs` calls is $O(n + m)$.
260
+
The runtime complexity of the sequence of `dfs` calls is $O(n + m)$.
262
261
Considering the stack, its complexity amortizes to $O(n)$ since each node is only pushed and popped once.
263
262
The total runtime complexity is therefore $O(n + m)$.
264
263
265
-
As an additional remark, the roots are found in reversed topological ordering.
266
-
In the algorithm, the vertex is a a root if there are no edges to unclaimed vertices outside of its subtree, meaning all other reachable components are either in its subtree (and therefore their roots were already found) or they connect to already claimed vertices outside of the subtree (whose roots were also already found).
264
+
As an additional remark, the roots are found in reversed topological order.
265
+
In the algorithm, the vertex is a root if there are no edges to unclaimed vertices outside of its subtree, meaning all other reachable components are either in its subtree (and therefore their roots were already found) or they connect to already claimed vertices outside of the subtree (whose roots were also already found).
267
266
So all reachable components were already found, meaning they are introduced in a valid reversed topological ordering of the condensation graph.
0 commit comments