Topological Sorting
Decrease and Conquer Technique
Definition
Topological sorting for a directed acyclic graph(DAG)
Linear ordering of vertices
For every edge U-V of a directed graph,
For every edge U-V of a directed graph,
 Vertex u will come before vertex v in the ordering
Source Removal Algorithm
Direct implementation of the decrease and conquers
method
Steps
Identify a vertex(source) from a remaining digraph
Identify a vertex(source) from a remaining digraph
with no incoming edges
 If there are more than one such vertices, then break the tie
randomly.
Delete it along with all the edges outgoing from it
Solution: deleted order of the vertices
Example
Consider a set of 5 required courses {C1,C2,C3,C4,C5} a
part-time student has to take in some degree program.
The courses can be taken in any order as long as the
following course prerequisites are met:
C1 and C2 have no prerequisites
 C1 and C2 have no prerequisites
 C3 requires C1 and C2
 C4 requires C3
 C5 requires C3 and C4
The student can take only one course per term.
In which order should the student take the courses?
Digraph
Prerequisite structure of five courses
C1 and C2 have no prerequisites
C3 requires C1 and C2
 C3 requires C1 and C2
 C4 requires C3
 C5 requires C3 and C4
Illustration
Illustration
delete C1
C1
Topological
Sorting
Illustration
delete C1
Illustration
delete C1 delete C2
C1 C2
Topological
Sorting
Illustration
delete C1 delete C2
Illustration
delete C1 delete C2
delete C3
C1 C2 C3
Topological
Sorting
Illustration
delete C1 delete C2
delete C3
Illustration
delete C1 delete C2
delete C3
delete C4
C1 C2 C3 C4
Topological
Sorting
Illustration
delete C1 delete C2
delete C3
delete C4
Illustration
delete C1 delete C2
delete C3
delete C4
delete C5
C1 C2 C3 C4 C5
Topological
Sorting
Topological Sorting (Decrease and Conquer)

Topological Sorting (Decrease and Conquer)