Algorithm Search⌘K

Algorithmadvanced

Bounded-radius bounded-cost tree

Also called BRBC.

Cong and coauthors' routing tree that walks the MST and adds shortcuts to the source, so the radius is within 1 + eps of optimal and the cost within 1 + 2/eps of the MST.

Time
Θ(n^2) worst
Space
Θ(n) extra
Where
n = the number of pins
Properties
deterministicnot exactiterative
Origin
Jason Cong, Andrew B. Kahng, Gabriel Robins, Majid Sarrafzadeh, C. K. Wong, 1992

The bounded-radius bounded-cost (BRBC) tree of Jason Cong, Andrew Kahng, Gabriel Robins, Majid Sarrafzadeh and C. K. Wong is a routing tree for a net in electronic design automation (EDA) with proved bounds on both its length and its longest path from the source. Given a parameter ε>0\varepsilon > 0, it walks around the minimum spanning tree of the pins and, whenever the walk has gone more than εR\varepsilon R since the last shortcut, adds a direct edge from the source to the current pin, where RR is the largest distance from the source to a pin. A shortest path tree of the result has radius at most (1+ε)R(1 + \varepsilon) R and cost at most (1+2/ε)(1 + 2/\varepsilon) times the minimum spanning tree. Small ε\varepsilon gives short paths and more wire; large ε\varepsilon gives a tree close to the minimum spanning tree.

In plain words

The driver of a net sends a signal to many sinks. The minimum spanning tree uses the least wire, but a sink can be far from the driver along the tree. A direct wire to every sink gives the shortest paths, but too much wire.

Start with the minimum spanning tree. Walk around it, along every edge down and back up, as you would trace its outline with a pencil. Keep a counter of how far you have walked. When the counter passes εR\varepsilon R, add a wire straight from the driver to the sink you are at, and reset the counter.

Every sink is then close, along the walk, to a sink with a direct wire, so its path from the driver is short. The walk has a fixed length, twice the spanning tree, so not many direct wires are added, and the extra wire is limited too.

The problem

The input is a set of nn points with a source ss, and a metric dist\mathrm{dist}, in routing the L1 distance. For a tree rooted at ss, the cost is the sum of its edge lengths and the radius is the largest path length d(v)d(v) from ss to a point vv in the tree. Let R=max⁡vdist(s,v)R = \max_v \mathrm{dist}(s, v), a lower bound on the radius of every tree, and let MST\mathrm{MST} be the cost of a minimum spanning tree, a lower bound on the cost of every spanning tree. Given ε>0\varepsilon > 0, the task is a spanning tree with radius at most (1+ε)R(1 + \varepsilon) R and cost within a constant factor of MST\mathrm{MST} that depends only on ε\varepsilon.

The algorithm

  1. BRBC(points, s, ε)
  2. 1Q ← a minimum spanning tree of the points; R ← max_v dist(s, v)
  3. 2run ← 0
  4. 3for each step from u to v of the depth-first tour of Q from s do
  5. 4run ← run + dist(u, v)
  6. 5if run > ε · R then
  7. 6if v ≠ s and v has no edge to s yet then add the edge (s, v) to Q
  8. 7run ← 0
  9. 8return a shortest path tree from s in the graph Q, found with Dijkstra's algorithm

The depth-first tour goes down each tree edge to a child and back up, so it has 2(n−1)2(n - 1) steps and length 2⋅MST2 \cdot \mathrm{MST}. The graph QQ after line L7 is the tree plus at most n−1n - 1 shortcuts, so the shortest path tree of line L8 is cheap to find.

Example

Take nine points that run up, across and down, with the source at the bottom left:

p0=(0,0)p_0 = (0, 0), p1=(1,3)p_1 = (1, 3), p2=(2,6)p_2 = (2, 6), p3=(3,9)p_3 = (3, 9), p4=(6,9)p_4 = (6, 9), p5=(9,9)p_5 = (9, 9), p6=(9,6)p_6 = (9, 6), p7=(9,3)p_7 = (9, 3), p8=(9,0)p_8 = (9, 0).

The minimum spanning tree is the chain p0,…,p8p_0, \ldots, p_8 with cost 27, and R=18R = 18, the distance to p5p_5. In the chain, p8p_8 is 27 away from the source. Take ε=1\varepsilon = 1, so the threshold is 18.

step of the tour run after the step action
p0p_0 to p5p_5 4, 8, 12, 15, 18 none, 18 is not more than 18
p5p_5 to p6p_6 21 add (p0,p6)(p_0, p_6) of length 15, reset
p6p_6 to p8p_8, back to p4p_4 3, 6, 9, 12, 15, 18 none
p4p_4 to p3p_3 21 add (p0,p3)(p_0, p_3) of length 12, reset
p3p_3 back to p0p_0 4, 8, 12 none

The shortest path tree of the chain plus the two shortcuts gives the path lengths 0,4,8,12,15,18,15,18,210, 4, 8, 12, 15, 18, 15, 18, 21, so the radius is 21, within the bound (1+1)⋅18=36(1 + 1) \cdot 18 = 36. Its edges are p0p1p_0 p_1, p1p2p_1 p_2, p0p3p_0 p_3, p3p4p_3 p_4, p4p5p_4 p_5, p0p6p_0 p_6, p6p7p_6 p_7 and p7p8p_7 p_8, of cost 47, within the bound 3⋅27=813 \cdot 27 = 81.

ε\varepsilon shortcuts to cost radius
1/4 p2,p4,p6,p8p_2, p_4, p_6, p_8 61 18
1/2 p3,p7,p5,p2p_3, p_7, p_5, p_2 63 18
1 p6,p3p_6, p_3 47 21
2 p4p_4 39 27
100 none 27 27

A smaller ε\varepsilon is not always cheaper for the same radius: ε=1/2\varepsilon = 1/2 adds four shortcuts and costs more than ε=1/4\varepsilon = 1/4. The Prim-Dijkstra tradeoff with c=1/2c = 1/2 reaches radius 18 here at cost 33.

Correctness

The proof shows the following.

  • A spanning tree. The graph QQ is connected, since it contains the minimum spanning tree, so the shortest path tree of line L8 spans all points.
  • Radius. Every point vv is reached on the tour at a moment when the run since the last reset is at most εR\varepsilon R. The last reset happened at the source or at a point ww with an edge to the source, so d(w)≤Rd(w) \le R, and the tree path from ww to vv is no longer than that part of the tour. So d(v)≤R+εRd(v) \le R + \varepsilon R.
  • Cost. Each shortcut uses up a part of the tour of length more than εR\varepsilon R, and these parts do not overlap. The tour has length 2⋅MST2 \cdot \mathrm{MST}, so there are fewer than 2⋅MST/(εR)2 \cdot \mathrm{MST} / (\varepsilon R) shortcuts, each of length at most RR. The shortest path tree is a subgraph of QQ, so its cost is at most MST+2⋅MST/ε\mathrm{MST} + 2 \cdot \mathrm{MST}/\varepsilon.
Proof: The BRBC tree has radius at most (1 + ε) R and cost at most (1 + 2/ε) times the minimum spanning treefull

Let the points have source ss and a metric dist\mathrm{dist}. Let MM be the minimum spanning tree of line L1 with cost MST\mathrm{MST}, let R=max⁡vdist(s,v)R = \max_v \mathrm{dist}(s, v), and fix ε>0\varepsilon > 0. The depth-first tour of MM from ss is the sequence of points t0=s,t1,…,t2n−2=st_0 = s, t_1, \ldots, t_{2n-2} = s in which each step goes along a tree edge, down to a child or back up to the parent. Each tree edge is used twice, so the tour has length 2⋅MST2 \cdot \mathrm{MST}, and every point appears in it. Let QQ be the graph at line L8, and let d(v)d(v) be the distance from ss to vv in QQ, which is the path length in the shortest path tree of line L8.

Lemma 1 (spanning tree). The output is a spanning tree of all points rooted at ss, and its path lengths are d(v)d(v).

Proof. QQ contains MM, so it is connected. Dijkstra's algorithm from ss on the connected graph QQ with lengths that are not negative gives a shortest path tree that spans all points, with path lengths d(v)d(v). □\square

Lemma 2 (reset points). Call tit_i a reset point if line L7 runs after the step to tit_i, and also call t0=st_0 = s a reset point. Every reset point ww has d(w)≤dist(s,w)≤Rd(w) \le \mathrm{dist}(s, w) \le R.

Proof. If w=sw = s, then d(w)=0d(w) = 0. Otherwise line L6 makes sure that QQ has the edge swsw, either added now or before, so d(w)≤dist(s,w)d(w) \le \mathrm{dist}(s, w). □\square

Lemma 3 (tour segments). If tit_i and tjt_j with i<ji < j are points of the tour, then the distance between them in MM is at most the length of the tour from tit_i to tjt_j.

Proof. The tour from tit_i to tjt_j is a walk in MM between these points, and the tree path is the shortest walk in a tree, since every walk between two vertices of a tree uses each edge of the path between them. □\square

Theorem 1 (radius). For every point vv, d(v)≤(1+ε)Rd(v) \le (1 + \varepsilon) R.

Proof. Let tj=vt_j = v be the first time the tour reaches vv, and let tit_i, i≤ji \le j, be the last reset point at or before position jj. If i=ji = j, Lemma 2 gives d(v)≤Rd(v) \le R. Otherwise no reset happened after the steps to ti+1,…,tjt_{i+1}, \ldots, t_j, so after each of these steps the run was at most εR\varepsilon R. The run after the step to tjt_j is the length of the tour from tit_i to tjt_j, so this length is at most εR\varepsilon R. By Lemma 3 and since M⊆QM \subseteq Q, d(v)≤d(ti)+εR≤R+εRd(v) \le d(t_i) + \varepsilon R \le R + \varepsilon R, using Lemma 2. □\square

Theorem 2 (cost). The output costs at most (1+2/ε)⋅MST(1 + 2/\varepsilon) \cdot \mathrm{MST}.

Proof. Let the reset points other than t0t_0 be ti1,…,tikt_{i_1}, \ldots, t_{i_k} in tour order, and set i0=0i_0 = 0. The run is reset after each, so the tour from tim−1t_{i_{m-1}} to timt_{i_m} has length more than εR\varepsilon R, by the test of line L5. These kk parts of the tour do not overlap, so kεR<2⋅MSTk \varepsilon R < 2 \cdot \mathrm{MST} when k≥1k \ge 1, and k≤2⋅MST/(εR)k \le 2 \cdot \mathrm{MST} / (\varepsilon R) in all cases. Each shortcut is added at a reset point, at most one per reset, and has length dist(s,w)≤R\mathrm{dist}(s, w) \le R. So the total length of QQ is at most MST+kR≤MST+2⋅MST/ε\mathrm{MST} + k R \le \mathrm{MST} + 2 \cdot \mathrm{MST} / \varepsilon. The output tree is a subgraph of QQ, so it costs no more. If R=0R = 0, all points coincide with ss, every cost is 0, and the bound holds. □\square

Running time. Line L1 takes Θ(n2)\Theta(n^2) with Prim's algorithm on all pairs. The tour has 2(n−1)2(n - 1) steps, each O(1)O(1) with a stack. QQ has at most (n−1)+(n−1)(n - 1) + (n - 1) edges, so Dijkstra's algorithm with a binary heap takes O(nlog⁡n)O(n \log n). The total is Θ(n2)\Theta(n^2) time and Θ(n)\Theta(n) space. □\square

Complexity

  • Time. The minimum spanning tree with Prim's algorithm on all pairs takes Θ(n2)\Theta(n^2). The tour has 2(n−1)2(n - 1) steps of O(1)O(1) each. Dijkstra's algorithm with a binary heap on QQ, which has at most 2(n−1)2(n - 1) edges, takes O(nlog⁡n)O(n \log n). The total is Θ(n2)\Theta(n^2), or O(nlog⁡n)O(n \log n) with the rectilinear minimum spanning tree in the L1 metric.
  • Space. The tree, the shortcuts, the tour stack and the distances take Θ(n)\Theta(n).

Properties

  • What is proved. For every ε>0\varepsilon > 0 the result is a spanning tree with radius at most (1+ε)R(1 + \varepsilon) R and cost at most (1+2/ε)⋅MST(1 + 2/\varepsilon) \cdot \mathrm{MST}. As ε→0\varepsilon \to 0 the radius goes to RR, and as ε→∞\varepsilon \to \infty the cost bound goes to MST\mathrm{MST}.
  • The tradeoff is real. Some point sets have no tree that is near both lower bounds at once. For the source at (0,0)(0, 0) and the points (i,k−i)(i, k - i) for i=0,…,ki = 0, \ldots, k, every point is at distance kk from the source, so a tree of radius exactly R=kR = k must join each point straight to the source and costs (k+1)k(k + 1) k, while the minimum spanning tree costs 3k3k.
  • What is measured. On 100 random nets of 30 points with coordinates from 0 to 999, the source being the first point (Python random.Random(2027)):
ε\varepsilon mean cost / MST worst cost / MST mean radius / RR worst radius / RR
1/4 2.670 3.584 1.030 1.202
1/2 2.106 2.571 1.049 1.224
1 1.617 1.919 1.102 1.439
2 1.307 1.522 1.256 2.017

All values are within the proved bounds, and far inside the cost bound. On the same nets the Prim-Dijkstra tree with c=1/2c = 1/2 had a mean cost ratio of 1.150 and a mean radius ratio of 1.054. These are toy inputs, not benchmark results.

  • Deterministic. The tour visits children in the order of their index, and ties in the shortest path tree go to the first path found.

Variants and improvements

  • Steiner trees. The output is a spanning tree. Routers turn it into a rectilinear Steiner tree by merging overlapping wires, which lowers the cost and does not make any path longer, so both bounds still hold.
  • Per-sink bounds. Later constructions bound each path by its own lower bound, d(v)≤(1+ε)dist(s,v)d(v) \le (1 + \varepsilon) \mathrm{dist}(s, v) for every vv, with a cost bound of the same form. These trees are called light approximate shortest-path trees in the work of Khuller, Raghavachari and Young.
  • Prim-Dijkstra. The Prim-Dijkstra tradeoff has no proved cost bound but often gives better trees in practice, as in the measurements above.
  • Arborescences. If every path must be shortest, the tree is a rectilinear Steiner arborescence, the Steiner form of the case ε=0\varepsilon = 0.

When to use it

  • When a routing tree must come with a guarantee on both its delay, through the radius, and its wire, through the cost.
  • As a baseline with proved bounds when testing timing-driven tree heuristics.

When the best practical tradeoff matters more than a guarantee, try the Prim-Dijkstra tradeoff for a few values of cc. When a better delay model than the path length is needed, evaluate the trees with the Elmore delay.

Pitfalls

  • Taking R as the radius of the MST. The threshold uses R=max⁡vdist(s,v)R = \max_v \mathrm{dist}(s, v), the distance in the plane, not the radius of the spanning tree. With the tree radius the threshold is larger, and the bound (1+ε)R(1 + \varepsilon) R on the radius no longer holds.
  • Keeping the walk tree as the output. The graph QQ after the shortcuts has cycles. The output is a shortest path tree of it, not QQ itself.
  • Resetting at the wrong time. The run must be reset whenever the threshold is passed, also when the point already has an edge to the source or is the source. Otherwise the cost bound breaks, since one shortcut would no longer stand for its own part of the tour.
  • Floating point thresholds. With ε\varepsilon as a float, a run that equals εR\varepsilon R may or may not pass it. Use exact numbers when the tie matters, as in the tests.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

bounded_radius_bounded_cost_tree.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bounded-radius-bounded-cost-tree/. The authors are listed in prov/58DVMM.jsonl.

import heapq
from fractions import Fraction
from typing import Sequence, Union

Point = tuple[int, int]
Number = Union[int, Fraction]


def l1(p: Point, q: Point) -> int:
    return abs(p[0] - q[0]) + abs(p[1] - q[1])


def mst_parent(points: Sequence[Point], source: int) -> list[int]:
    """Prim's minimum spanning tree under L1, rooted at the source. O(n^2)."""
    n = len(points)
    parent = [-1] * n
    best = [(l1(points[source], p), source) for p in points]
    used = [False] * n
    used[source] = True
    for _ in range(n - 1):
        v = min((i for i in range(n) if not used[i]), key=lambda i: (best[i][0], i))
        used[v] = True
        parent[v] = best[v][1]
        for w in range(n):
            if not used[w] and l1(points[v], points[w]) < best[w][0]:
                best[w] = (l1(points[v], points[w]), v)
    return parent


def brbc(points: Sequence[Point], eps: Number, source: int = 0) -> tuple[list[int], list[int], list[int]]:
    """Cong, Kahng, Robins, Sarrafzadeh and Wong's bounded-radius bounded-cost tree.

    Walks a depth-first tour of the L1 minimum spanning tree from the source and
    adds the edge (source, v) when the tour length since the last added edge
    exceeds eps * R, where R is the largest distance from the source. Returns
    (parent, d, shortcuts): the shortest path tree of the MST plus the added
    edges, the path lengths d from the source, and the points v that got an
    edge. For eps > 0, every d[v] <= (1 + eps) R and the cost is at most
    (1 + 2 / eps) times the MST.
    """
    if eps <= 0:
        raise ValueError("eps must be positive")
    n = len(points)
    if n == 0:
        return [], [], []
    tparent = mst_parent(points, source)  # @line L1
    children: list[list[int]] = [[] for _ in range(n)]
    for v, u in enumerate(tparent):
        if u >= 0:
            children[u].append(v)
    R = max(l1(points[source], p) for p in points)
    adj: list[list[tuple[int, int]]] = [[] for _ in range(n)]
    for v, u in enumerate(tparent):
        if u >= 0:
            w = l1(points[u], points[v])
            adj[u].append((w, v))
            adj[v].append((w, u))
    shortcuts: list[int] = []
    has_edge: set[int] = set()
    run: Number = 0  # @line L2
    stack = [(source, 0)]  # (vertex, index of the next child) for the depth-first tour
    while stack:  # @line L3
        u, k = stack[-1]
        if k < len(children[u]):
            stack[-1] = (u, k + 1)
            v = children[u][k]
            nxt = v
            stack.append((v, 0))
        else:
            stack.pop()
            if not stack:
                break
            nxt = stack[-1][0]
        run += l1(points[u], points[nxt])  # @line L4
        if run > eps * R:  # @line L5
            # The source and points that already have an edge need no new one.
            if nxt != source and nxt not in has_edge:  # @line L6
                has_edge.add(nxt)
                shortcuts.append(nxt)
                w = l1(points[source], points[nxt])
                adj[source].append((w, nxt))
                adj[nxt].append((w, source))
            run = 0  # @line L7
    dist = [-1] * n
    parent = [-1] * n
    heap = [(0, source, -1)]  # @line L8
    while heap:
        du, u, pu = heapq.heappop(heap)
        if dist[u] >= 0:
            continue
        dist[u] = du
        parent[u] = pu
        for w, v in adj[u]:
            if dist[v] < 0:
                heapq.heappush(heap, (du + w, v, u))
    return parent, dist, shortcuts


def tree_cost(points: Sequence[Point], parent: Sequence[int]) -> int:
    return sum(l1(points[v], points[u]) for v, u in enumerate(parent) if u >= 0)
test_bounded_radius_bounded_cost_tree.py 73 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/bounded-radius-bounded-cost-tree/. The authors are listed in prov/58DVMM.jsonl.

import random
from fractions import Fraction

from bounded_radius_bounded_cost_tree import brbc, l1, tree_cost


def mst_length(pts: list[tuple[int, int]]) -> int:
    """Kruskal on all pairs, written apart from the tree builder."""
    n = len(pts)
    parent = list(range(n))

    def find(a: int) -> int:
        while parent[a] != a:
            a = parent[a]
        return a

    total = 0
    for d, i, j in sorted((l1(pts[i], pts[j]), i, j) for i in range(n) for j in range(i + 1, n)):
        if find(i) != find(j):
            parent[find(i)] = find(j)
            total += d
    return total


def path_lengths(pts: list[tuple[int, int]], parent: list[int], source: int) -> list[int]:
    """Length of the tree path from the source to each point, by walking up the parents."""
    out = []
    for v in range(len(pts)):
        total, seen = 0, set()
        while v != source:
            assert v not in seen and parent[v] >= 0
            seen.add(v)
            total += l1(pts[v], pts[parent[v]])
            v = parent[v]
        out.append(total)
    return out


EXAMPLE = [(0, 0), (1, 3), (2, 6), (3, 9), (6, 9), (9, 9), (9, 6), (9, 3), (9, 0)]


def test_example() -> None:
    parent, d, cuts = brbc(EXAMPLE, 1)
    assert mst_length(EXAMPLE) == 27 and max(l1(EXAMPLE[0], p) for p in EXAMPLE) == 18
    assert cuts == [6, 3]
    assert d == [0, 4, 8, 12, 15, 18, 15, 18, 21]
    assert tree_cost(EXAMPLE, parent) == 47
    parent, d, cuts = brbc(EXAMPLE, 100)
    assert cuts == [] and tree_cost(EXAMPLE, parent) == 27 and max(d) == 27


def test_edges() -> None:
    assert brbc([], 1) == ([], [], [])
    assert brbc([(5, 5)], 1) == ([-1], [0], [])
    parent, d, _ = brbc([(0, 0), (3, 1)], Fraction(1, 4))
    assert parent == [-1, 0] and d == [0, 4]


def test_bounds(seed: int = 37) -> None:
    rng = random.Random(seed)
    for _ in range(300):
        n = rng.randint(1, 16)
        pts = [(rng.randint(0, 40), rng.randint(0, 40)) for _ in range(n)]
        s = rng.randrange(n)
        eps = rng.choice([Fraction(1, 10), Fraction(1, 4), Fraction(1, 2), Fraction(1), Fraction(3)])
        parent, d, _ = brbc(pts, eps, s)
        assert d == path_lengths(pts, parent, s)
        R = max(l1(pts[s], p) for p in pts)
        assert all(x <= (1 + eps) * R for x in d)
        assert tree_cost(pts, parent) <= (1 + 2 / eps) * mst_length(pts)

History

The minimum spanning tree and the shortest path tree were the two classical routing trees when wire delay began to matter in the early 1990s. Jason Cong, Andrew Kahng, Gabriel Robins, Majid Sarrafzadeh and C. K. Wong presented the BRBC construction, with its bounds on both the radius and the cost, at ISCAS and in IEEE Transactions on Computer-Aided Design in 1992, under the title of provably good performance-driven global routing. Charles Alpert and coauthors compared it with their Prim-Dijkstra trees in 1995. In network design, Samir Khuller, Balaji Raghavachari and Neal Young gave trees with a bound for each path in 1995.

References

  1. J. Cong, A. B. Kahng, G. Robins, M. Sarrafzadeh and C. K. Wong, Provably good performance-driven global routing, IEEE Transactions on Computer-Aided Design 11(6), 739 to 752, 1992, the BRBC algorithm and the bounds (1 + ε) R on the radius and (1 + 2/ε) on the cost ratio
  2. C. J. Alpert, T. C. Hu, J. H. Huang, A. B. Kahng and D. Karger, Prim-Dijkstra tradeoffs for improved performance-driven routing tree design, IEEE Transactions on Computer-Aided Design 14(7), 890 to 896, 1995, the comparison of BRBC trees with the Prim-Dijkstra trees

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • at least three sources
  • a scene preset for the example