Question: Java program task : consider a set of five required courses {C1, C2, C3, C4, C5} a part-time student has to take in some degree
Java program task :
consider a set of five required courses {C1, C2, C3, C4, C5} a part-time student has to take in some degree program. The courses can be
taken in any order as long as the following course prerequisites are met: C1 and C2 have no prerequisites, C3 requires C1 and C2, C4 requires C3, and C5 requires C3 and C4. The student can take only one course per term. In which order should the student take the courses?
The situation can be modeled by a digraph in which vertices represent courses
and directed edges indicate prerequisite requirements. In terms of this digraph, the question is whether we can list its vertices in such an order that for every edge in the graph, the vertex where the edge starts is listed before the vertex where the edge ends.
How can I find such an ordering of this digraphs vertices using topological sorting?
for topological sorting to be possible, a digraph in question must not have a cycle.
The Java program should:
* represent the given digraph.
* check if it has a cycle or not using DFS traversal.
* if it doesnt, make the topological sorting for the digraph.
C1 C4 C3) C2 C5 Digraph representing the prerequisite structure of five courses
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
