Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started