Learn

Learning preferences

Make learning more comfortable. Changes apply immediately.

Enlarges page content, including diagrams and their labels. You can also use your browser’s zoom.

Choose the colours that are easiest for you to distinguish. Applies to lesson diagrams and lab plots. Labels, shapes, hatching and line patterns also distinguish meanings. Source photographs and raw image brightness stay unchanged; mask-only views are available for image overlays.

ExampleComparisonSample link

Saved in this browser on this device. Preferences are separate from progress backups.

Lesson 13 of 18

Order dependencies without inventing an order for cycles

Construct topological orders and prove why the algorithm detects cycles.

Loading your saved responses…

Try

Suppose tasks A and B must both precede C. The orders A,B,C and B,A,C both respect the dependencies. A topological ordering need not be unique; it is any linear order placing the tail of every directed edge before its head.

Predict

Predict why a directed cycle prevents such an order. A→B→C→A would require A before itself by transitivity. A DAG is a directed acyclic graph. Indegree counts incoming edges; outdegree counts outgoing ones.

Experiment

Use the small dependency diagram. Repeatedly choose an indegree-zero remaining vertex, record it and remove its outgoing edges. Track indegrees after each removal. Then add a reverse edge that creates a cycle and determine where the process becomes stuck.

Order dependencies without inventing an order for cycles: diagramTwo directed edges point from A and B into C; no edge connects A to B.ABC
Schematic dependency DAG: A and B both precede C. Either A,B,C or B,A,C is a topological order. Arrow direction denotes prerequisite to dependent.

Understand

Worked source proof: every nonempty finite DAG has a source, a vertex with indegree zero. If not, follow a predecessor from each vertex indefinitely. A repeated vertex must eventually occur, yielding a directed cycle, contradiction. This existence theorem justifies each step of Kahn’s algorithm.

When a source is removed, every incoming predecessor has already been recorded, so no edge points backward in the final order. If a nonempty remainder has no source, the same predecessor argument certifies a cycle there. Empty completion is success; a partial order of removed vertices is not a full answer.

Invalid inference: a cycle in the undirected drawing forbids topological ordering. Directed orientation matters; a triangle A→B,A→C,B→C is acyclic.

Apply

Specify the edge direction as prerequisite-to-dependent or another stated convention. Check every edge against a proposed ordering. Different valid source choices may produce different correct orders, so tests should not demand one arbitrary order.

Continue

Depth: a partial order can be represented by a DAG with redundant transitive edges omitted or included. Topological sorting resolves precedence but does not by itself optimize elapsed time, resource use or parallel scheduling.

Apply · explain · revise

Practice and reasoning

Drafts save locally as you type. Reveal worked solutions when useful; the site remembers that exposure. Automatic matches check the requested answer, while written arguments require review against the rubric.

A DAG has vertices A,B,C and only edges A→C and B→C. How many topological orders?

Integers, fractions and finite decimals are accepted. Expressions such as sqrt(2) are not parsed by this checker.

Edges are A→B,A→D,C→D,B→D. What is D's indegree?

Integers, fractions and finite decimals are accepted. Expressions such as sqrt(2) are not parsed by this checker.

A finite directed graph has a topological ordering exactly when:

Your response

Kahn's topological-sort algorithm may next remove:

Your response

Prove every nonempty finite DAG has a vertex of indegree zero.

Structure your argument and preserve revisions

These optional planning fields save locally. Recording your response saves an immutable copy of the argument and these fields. Older records may contain only first/latest responses; missing intermediate revisions are not reconstructed.

Each field allows 2,000 characters. Keep a specific claim, state where it applies, cite the facts you use, and explain what still needs checking. Blank fields are allowed and are not evidence of mastery.

Explain why repeatedly removing an indegree-zero vertex produces a topological order, and what getting stuck means.

Structure your argument and preserve revisions

These optional planning fields save locally. Recording your response saves an immutable copy of the argument and these fields. Older records may contain only first/latest responses; missing intermediate revisions are not reconstructed.

Each field allows 2,000 characters. Keep a specific claim, state where it applies, cite the facts you use, and explain what still needs checking. Blank fields are allowed and are not evidence of mastery.

Reflect and continue

Before marking this lesson complete, explain one key idea without the worked solution and identify a condition that matters. Marking complete records participation, not independent mastery.