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/topological-sort.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -26,14 +26,14 @@ The example graph also has multiple topological orders, a second topological ord
26
26
27
27
A Topological order may**not exist** at all.
28
28
It only exists, if the directed graph contains no cycles.
29
-
Otherwise because there is a contradiction: if there is a cycle containing the vertices $a$ and $b$, then $a$ needs to have a smaller index than $b$ (since you can reach $b$ from $a$) and also a bigger one (as you can reach $a$ from $b$).
29
+
Otherwise, there is a contradiction: if there is a cycle containing the vertices $a$ and $b$, then $a$ needs to have a smaller index than $b$ (since you can reach $b$ from $a$) and also a bigger one (as you can reach $a$ from $b$).
30
30
The algorithm described in this article also shows by construction, that every acyclic directed graph contains at least one topological order.
31
31
32
-
A common problem in which topological sorting occurs is the following. There are $n$ variables with unknown values. For some variables we know that one of them is less than the other. You have to check whether these constraints are contradictory, and if not, output the variables in ascending order (if several answers are possible, output any of them). It is easy to notice that this is exactly the problem of finding topological order of a graph with $n$ vertices.
32
+
A common problem in which topological sorting occurs is the following. There are $n$ variables with unknown values. For some variables, we know that one of them is less than the other. You have to check whether these constraints are contradictory, and if not, output the variables in ascending order (if several answers are possible, output any of them). It is easy to notice that this is exactly the problem of finding the topological order of a graph with $n$ vertices.
33
33
34
34
##The Algorithm
35
35
36
-
To solve this problem we will use[depth-first search](depth-first-search.md).
36
+
To solve this problem, we will use[depth-first search](depth-first-search.md).
37
37
38
38
Let's assume that the graph is acyclic. What does the depth-first search do?