Data Structure: Topic: Topological Sorting
Data Structure: Topic: Topological Sorting
Presented by:
ADITYA MANDAL
FAWAZ MHD
PRITHWISH RAHUL
UNDER THE GUIDANCE OF
ARJUN KS MS. ABHIRAMI
ANUVIND PM (ASSISTANT PROFESSOR)
SOUMYAJIT ROY
SUBHRAJIT ROY
ALFIYA BANU
TAOKEER ALAM
TEAM MEMBERS
1. FAWAZ
2. RAHUL
3. ARJUN
4. ANUVIND
5. ADITYA
6. SOUMYAJIT
7. SUBHRAJIT
8. ALFIYA
9. TAOKEER
GRAPH
• A structure amounting to a set of objects in which some
pairs of the objects are in some sense "related".
• Nodes and edges are the fundamental unit of which
graphs are formed
B E
Nodes/vertices
A D
Edges
C F
Topological Sorting
• Instruction Scheduling.
• Data Serialization.
PRACTICE PROBLEMS BASED ON
TOPOLOGICAL SORT-
Problem:
The number of different topological orderings for the graph shown is ________ ?
Solution-
Step-01:
Write in-degree of each vertex-
Step-02:
Now, since vertex-A has least in-degree, so remove vertex-A and its
associated edges and update in-degree of other vertices.
Step-03:
Now, since vertex-B has least in-degree, so remove vertex-B and its
associated edges and update in-degree of other vertices.
Step-04:
Now, since we have two vertices with least in-degree, so we have 2
choices and therefore we have 2 cases-
Case-01: Remove vertex-C and its associated edges and update in-
degree of other vertices.
Case-02: Remove vertex-D and its associated edges and update in-
degree of other vertices.
Step-05:
Now, we will continue with the above two cases separately in the similar manner.
• In case-01, first remove vertex-D since it has least in-degree and then remove
the remaining vertex-E.
• In case-02, first remove vertex-C since it has least in-degree and then remove
the remaining vertex-E.
Thus, for the given graph, 2 different topological orderings are possible-
• ABCDE
• ABDCE