Graphs · Exercise 43 of 100
Topological sort by prerequisites
A topological ordering puts each prerequisite before the task that needs it. Choose a remaining task with no incoming edges, mark it complete and remove it and its outgoing edges. If tasks remain but none is ready, the remaining graph contains a cycle.
Try it yourself
Ink must finish before Box, and both Box and Kit must finish before Map. If you always choose the alphabetically earliest ready task, which task runs second?
One-step hint
Write down the tasks with no unfinished prerequisites. After the first choice, update that list before applying alphabetical order again.
Worked solution
- Ink and Kit are ready at the start, so the alphabetical rule selects Ink first.
- Finishing Ink makes Box ready. Box comes before Kit alphabetically, so Box runs second.