0

How should one go about this kind of problems? I'm supposed to use a graph structure for this.

Say I have a file containing a couple of courses with their prerequisites.

I have to organize the semester with courses while respecting prerequisites and the max number of courses per semester. The first semester should be filled to the max capacity if possible, then the second, the third, etc.

For example:
max : 3, path to INF7
1: INF1, INF2, INF3
2: INF4, INF5,
3: INF6
4: INF7

Of course a course that has another course as its prerequisite can't be completed before or while the prerequisite is in progress.

I thought about doing a graph of string representing the course and find all paths from a node to another node then build a set with that, but I am stuck at this step.

Any advice is appreciated.

greybeard
  • 1,041
  • 2
  • 9
  • 23
JavaRun
  • 1
  • 1
  • This can be achieved using graph coloring. – idmean Aug 06 '21 at 05:27
  • If I understand your problem correctly, you can represent this as a DAG then perform topological sorting so you will have a sequence of courses that satisfies the prerequisites. Then, scan this sequence left-to-right, filling your semesters up to max capacity. – Russel Aug 08 '21 at 04:36

0 Answers0