Question
Write a python program that uses topological sort based on Kahn's algorithmn. It should read from a testcase.list and Your program must take a list
Write a python program that uses topological sort based on Kahn's algorithmn. It should read from a testcase.list and
Your program must take a list of dependent tasks and either output a valid order in which to perform them or the single word cycle.
Your program will accept a number of lines of textual input (via standard input). There are no command line arguments you must always read from standard input. Do not open a named file. Instead, always read from standard input.
The text input will contain a non-zero but even number of lines. Every two lines represent a pair of tasks. The first line gives the name of the task, the second line gives the name of the task that it depends on. This text input is also called the task list.
The task list will contain only standard ASCII characters (no UTF-8 Unicode or special accents). The goal is to rest programming and program language concepts, not your internationalization abilities.
Each task name starts at the beginning of the line and extends all the way up to (but not including) the end of that line. So, the newline or carriage return characters or are not part of the task list name.
Example task list:
learn OCaml read the OCaml tutorial do assignment 1 learn OCaml
L Empty list that will contain the sorted elements S Set of all nodes with no incoming edge while S is not empty do remove a node n from S add n to L for each node m with an edge e from n to m do remove edge e from the graph if m has no other incoming edges then insert m into S if graph has edges then return error (graph has at least one cycle) else return L (a topologically sorted order)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started