Use backtracking algorithm to solve this problem and provide some nice comments.
ID: 3538884 • Letter: U
Question
Use backtracking algorithm to solve this problem and provide some nice comments.
A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, csl23, cs456. and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has 110 prerequisites. cs456 is only offered in the spring semester and has both csl23 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, csl23 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs7S9 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input: There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers nExplanation / Answer
need more time
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.