Chapter 3: Q16E (page 109)
Suppose a CS curriculum consists of n courses, all of them mandatory. The prerequisite graph G has a node for each course, and an edge from course v to course w if and only if v is a prerequisite for w. Find an algorithm that works directly with this graph representation, and computes the minimum number of semesters necessary to complete the curriculum (assume that a student can take any number of courses in one semester). The running time of your algorithm should be linear.
Short Answer
The linear algorithm that computes the minimum number of semesters necessary to complete the curriculum in linear time is as follows:
Input: Graph G
Output: number of required semesters.
Add n vertices that has to the first queue
if
add nto the second queue
process second queue
if semester coincides with class schedule
return n