learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Algorithm Selection

Select an algorithm and generate steps to begin visualization

Chu-Liu/Edmonds Algorithm

The minimum spanning tree, with one-way streets

Finds the cheapest arcs that reach every vertex from a root: each vertex takes its cheapest incoming arc, and any cycle this makes is contracted and solved again

Time: O(n·m)
Space: O(n + m)
Use Case: Dependency parsing in NLP, broadcast networks, phylogenetics, directed network design
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Minimum Arborescence (Chu–Liu/Edmonds)

An arborescence is a spanning tree with directions: one root, and from it exactly one directed path to every other vertex, so every vertex except the root has exactly one incoming arc. The minimum arborescence is the cheapest such tree, the directed counterpart of a minimum spanning tree. Prim and Kruskal fail here: in a directed graph the cheapest arcs may point the wrong way, and a greedy choice can leave a vertex that the root cannot reach. Yoeng-Jin Chu and Tseng-Hong Liu (1965) and, independently, Jack Edmonds (1967) found the algorithm.

How it works

Every vertex other than the root picks its cheapest incoming arc. If the picks contain no cycle, they already form the answer, since no tree can do better than the cheapest arc into each vertex. If they do contain a cycle, the cycle is merged into a single vertex. An arc x → v entering the cycle would replace v's cycle arc, so its cost is lowered by the cost of that arc. The algorithm runs again on the smaller graph, and when the cycle is expanded the arc chosen to enter it decides which cycle arc to drop. This gives O(n·m) time, and Tarjan's version with mergeable heaps runs in O(m log n). The visualizer draws the picks in green, a cycle in magenta, colours each merged group, lists the adjusted costs and ends with the arborescence and its total.

Applications

Dependency parsers in natural language processing score every possible head for every word and take the maximum arborescence as the sentence's structure, which is how non-projective parsers find crossing links. The same problem appears when one sender must reach everyone in a network of one-way links at least cost, in phylogenetics when choosing which variant descends from which, and as a building block in directed network design. If a vertex cannot be reached from the root at all, no arborescence exists and the run reports it.

Pseudocode

A recursive description: pick, look for a cycle, contract, solve the smaller problem, expand.

ChuLiuEdmonds(G, r):
    for each vertex v != r:
        in(v) = cheapest arc entering v      // none: no arborescence
    if the arcs in(v) form no cycle:
        return them                          // already optimal
    C = a cycle among them
    contract C into one vertex c
    for each arc x → v with v in C and x not in C:
        cost(x → c) = cost(x → v) - cost(in(v))
    A = ChuLiuEdmonds(contracted G, r)
    expand c: keep A and the arcs of C,
        except in(v) for the vertex v that A enters
    return the result

The adjusted cost is what entering the cycle at v really costs: the arc x → v comes in, and v no longer needs its cycle arc. There is always a best arborescence that keeps all of the cycle but one arc, so it enters the cycle exactly once. Arcs between two vertices of the cycle disappear in the contraction.

Worked example, step by step

The six-vertex example on this page, rooted at A.

Example graph: Arcs A → B (9), A → C (8), A → E (10), B → C (2), C → B (3), B → D (6), C → D (4), D → E (3), E → D (1), D → F (5), E → F (2).

  1. Cheapest arcs in. B takes C → B (3), C takes B → C (2), D takes E → D (1), E takes D → E (3) and F takes E → F (2). They cost only 11, but no arc from A is among them: B and C pick each other, and so do D and E.
  2. Contract B, C. B and C merge into one vertex. A → B now costs 9 − 3 = 6, because it replaces C → B, and A → C costs 8 − 2 = 6, because it replaces B → C.
  3. Level 1 picks. The merged vertex takes A → B at 6, with A → C tied at 6. D and E still pick each other, a second cycle.
  4. Contract D, E. The arcs into the merged D, E are lowered: C → D to 4 − 1 = 3, B → D to 6 − 1 = 5 and A → E to 10 − 3 = 7.
  5. Level 2 picks. The D, E vertex takes C → D at 3 and F keeps E → F. No cycle is left, so the smallest problem is solved.
  6. Expand. C → D enters the D, E cycle at D, so E → D is dropped and D → E stays. A → B enters the B, C cycle at B, so C → B is dropped and B → C stays.

The minimum arborescence is A → B (9), B → C (2), C → D (4), D → E (3), E → F (2), total 20. Taking the tied A → C instead gives A → C, C → B and the same total 20, so this example has two optimal answers.

Complexity, and where it comes from

Time: O(n·m) · Space: O(n + m)

Each round picks the cheapest incoming arcs and looks for a cycle in O(m). Each contraction removes at least one vertex, so there are at most n − 1 rounds, O(n·m) in all. Tarjan (1977) kept the incoming arcs in mergeable heaps and reached O(m log n), and Gabow, Galil, Spencer and Tarjan (1986) reached O(m + n log n).

When to use Minimum Arborescence (Chu–Liu/Edmonds), and when not to

Related tree problems and when each one applies.

AlternativePrefer it whenCost
Prim or KruskalThe graph is undirected. Then any vertex can be the root, and a minimum spanning tree is the answer.O(m log n)
Shortest path tree (Dijkstra)Each vertex must be reached by its cheapest path from the root, rather than the whole tree being as cheap as possible. The two trees differ in general.O(m + n log n)
Tarjan, or Gabow et al.Large graphs. The same answer, with mergeable heaps instead of rescanning every arc each round.O(m log n) or O(m + n log n)

Common pitfalls

  • Growing the tree like Prim. Adding the cheapest arc out of the tree so far is wrong for directed graphs. With arcs A → B (2), A → C (3) and C → B (1), it takes A → B first and ends at 5, while A → C and C → B cost 4. On this page it happens to reach 20, which hides the problem.
  • Forgetting to adjust the costs. After a contraction, an arc entering the cycle must be compared by what it costs on top of the cycle, w(x → v) − w(in(v)), not by its raw cost. Raw costs pick the wrong entry point.
  • Not checking reachability. If some vertex cannot be reached from the root at all, no arborescence exists and the picks do not form one. Check first with a search from the root. The visualizer stops and names the vertex, or the merged group, that no arc enters.

Frequently asked questions

What is an arborescence?
A directed spanning tree with a root: every vertex can be reached from the root along exactly one directed path. Equivalently, the root has no incoming arc, every other vertex has exactly one, and there is no cycle.
How do I get a maximum arborescence?
Negate all costs, or pick the most expensive incoming arc instead of the cheapest. Dependency parsers do this with the scores of word pairs.
What if the root is not given?
Add a new vertex with an arc of the same large cost M to every vertex and root the problem there. If M exceeds the sum of all other costs, the best arborescence uses exactly one of the new arcs, and its target is the best root.

Related algorithms: Prim's MST Algorithm, Kruskal's MST Algorithm, Borůvka's Algorithm, Steiner Tree, Topological Sort

An example graph: you can change it, or start blank.

Zoom Controls

30%
Nodes: 6
Edges: 11