You have to sequence the order of (mathrm{n}) jobs that are numbered from 0 to (n-1) on

Question:

You have to sequence the order of \(\mathrm{n}\) jobs that are numbered from 0 to \(n-1\) on a server. Some of the jobs must complete before others can begin. Write a program TopologicaT Sorter that takes a command-line argument \(n\) and a sequence on standard input of ordered pairs of jobs \(i j\), and then prints a sequence of integers such that for each pair \(i j\) in the input, job \(i\) appears before job \(j\). Use the following algorithm: First, from the input, build, for each job, (i) a queue of the jobs that must follow it and (ii) its indegree (the number of jobs that must come before it). Then, build a queue of all nodes whose indegree is 0 and repeatedly delete any job with a 0 indegree, maintaining all the data structures. This process has many applications. For example, you can use it to model course prerequisites for your major so that you can find a sequence of courses to take so that you can graduate.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: