Question: In class we saw an algorithm for finding a topological sort of the vertices in a directed, acylic graph. The algorithm was based on finding
In class we saw an algorithm for finding a topological sort of the vertices in a directed, acylic graph. The algorithm was based on finding vindgree for each vertex in the graph, and it used an external list L
Compute indegree of each vertex and store the indegree in v:indegree.
For all v in V if v:indegree then add v to the list L
Repeat until L is empty:
Remove a vertex u from L and place it at the end of T
For all v in Adj u
v:indegree v:indegree
if v:indegree
add v to L
Suppose we wish to update this algorithm in order to solve the following problem:
Let G be a directed, acyclic graph, where each vertex has a diculty rating, vrate. The problem is to find a topological ordering of the vertices, one which prioritizes vertices of low rating before vertices of high rating. For example, if several orderings are possible, the goal is to prioritize vertices of lowest rating before those of higher rating, as long as it respects the topological sort.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
