0% found this document useful (0 votes)
92 views13 pages

Data Structure: Topic: Topological Sorting

This document discusses topological sorting of vertices in a directed acyclic graph (DAG). It defines topological sorting as a linear ordering of the vertices in a DAG such that if there is an edge from vertex U to vertex V, then U comes before V in the ordering. It provides an example of a DAG and applications of topological sorting like scheduling jobs and instruction scheduling. It also presents a practice problem on finding the number of topological orderings for a given graph.

Uploaded by

aditya mandal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views13 pages

Data Structure: Topic: Topological Sorting

This document discusses topological sorting of vertices in a directed acyclic graph (DAG). It defines topological sorting as a linear ordering of the vertices in a DAG such that if there is an edge from vertex U to vertex V, then U comes before V in the ordering. It provides an example of a DAG and applications of topological sorting like scheduling jobs and instruction scheduling. It also presents a practice problem on finding the number of topological orderings for a given graph.

Uploaded by

aditya mandal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

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

TOPOLOGICAL SORTING OF VERTICES OF A DIRECTED ACYCLIC


GRAPH (DAG) IS A LINEAR ORDERING OF THE VERTICES IN SUCH A
WAY THAT IF THERE IS AN EDGE IN THE DAG GOING FROM VERTEX
‘U’ TO VERTEX ‘V’, THEN ‘U’ COMES BEFORE ‘V’ IN THE ORDERING.
This is how an a Directed Acyclic Graph looks like
NOTES:-

• Directed Acyclic Graph (DAG) is a special kind of Abstract Syntax Tree.


1. Each node of it contains a unique value.
2. It does not contain any cycles in it, hence called Acyclic.

• Topological Sorting is not possible if the graph is not a Directed Acyclic


Graph.
• There may exist multiple topological orderings for a Directed Acyclic
Graph
Applications of Topological Sort-
• Scheduling jobs from the given dependencies
among jobs.

• Instruction Scheduling.

• Determining the order of compilation tasks to


perform in makefiles.

• 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

You might also like