Write Up ADSL Assignment 3 AVO Topological Sort
Write Up ADSL Assignment 3 AVO Topological Sort
Problem statement:
Objectives:
Understand the traversal of graph with dependencies of
nodes
To know the concept of topological ordering
To practically achieve topological ordering
Theory:
Note: Topological Sorting for a graph is not possible if the graph is not
a DAG.
DAGs are a special type of graphs in which each edge is directed such that
no cycle exists in the graph, before understanding why Topological sort
only exists for DAGs, lets first answer two questions:
Example:
Output:5 4 2 3 1 0
Explanation:
The first vertex in topological sorting is always a vertex with an in-degree
of 0 (a vertex with no incoming edges). A topological sorting of the
following graph is “5 4 2 3 1 0”. There can be more than one topological
sorting for a graph. Another topological sorting of the following graph is “4
5 2 3 1 0”.
Analogy:
Algorithm:
1. Compute the indegree of all vertices.
Time complexity:
Discuss the time complexity of following function with respect to best case
and worst case considering both ways of implementing a graph.
Test Cases:
Practice problem:
List & Find the number of different topological orderings possible for the
given graph-