Académique Documents
Professionnel Documents
Culture Documents
In computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that, for every edge uv, u comes before v in the ordering. For instance, the vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one task must be performed before another; in this application, a topological ordering is just a valid sequence for the tasks. A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG). Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time.
Jasvinder Singh, jasvinder.singh13@rediffmail.com
1
F H
dfs(A)
F H
dfs(A) dfs(D)
F H
F H
F H
F H
F H 7
H 7
dfs(A) dfs(D)
H 7
10
dfs(A) dfs(D)
H 7
11
dfs(A)
D 4
H 7
12
dfs(A)
D 4
H 7
13
D 4
H 7
14
dfs(B)
D 4
H 7
15
dfs(B)
D 4
H 7
16
D 4
H 7
17
dfs(C)
D 4
H 7
18
dfs(C)
D 4
H 7
19
dfs(C)
D 4
H 7
20
dfs(C)
D 4
H 7
21
dfs(C) dfs(G)
D 4
H 7
22
dfs(C)
D 4
H 7
23
D 4
H 7
24
D 4
H 7
Topological order: C G B A D E F H
Jasvinder Singh, jasvinder.singh13@rediffmail.com
25