Skip to content

[Model] RootedTreeArrangement #407

@isPANN

Description

@isPANN

Motivation

ROOTED TREE ARRANGEMENT (P56) from Garey & Johnson, A1.3 GT45. An NP-complete graph arrangement problem that asks whether the vertices of a given graph can be embedded one-to-one into the nodes of a rooted tree such that every edge of the graph connects two vertices on the same root-to-leaf path, and the total edge-stretch (sum of tree distances over all graph edges) is bounded by K. This generalizes OPTIMAL LINEAR ARRANGEMENT (GT43) to tree-structured layouts. Gavril (1977) proved NP-completeness via reduction from OPTIMAL LINEAR ARRANGEMENT. The problem arises in file system layout, memory hierarchy design, and data structure optimization.

Associated rules:

  • R099: Rooted Tree Arrangement → Rooted Tree Storage Assignment (as source)
  • Reduced from OPTIMAL LINEAR ARRANGEMENT (per GJ book text, GT43 → GT45)

Definition

Name: RootedTreeArrangement
Canonical name: ROOTED TREE ARRANGEMENT
Reference: Garey & Johnson, Computers and Intractability, A1.3 GT45

Mathematical definition:

INSTANCE: Graph G = (V, E), positive integer K.
QUESTION: Is there a rooted tree T = (U, F), with |U| = |V|, and a one-to-one function f: V -> U such that for every edge {u,v} in E there is a simple path from the root that includes both f(u) and f(v) and such that if d(x,y) is the number of edges on the path from x to y in T, then sum_{{u,v} in E} d(f(u), f(v)) <= K?

Variables

  • Count: 2n variables, where n = |V|. The first n variables encode the tree topology as a parent array; the next n variables encode the bijection f.
  • Per-variable domain: Each variable takes values in {0, 1, ..., n-1}.
  • Encoding:
    • config[0..n] = parent array: config[i] is the parent of node i in the rooted tree T. The root r satisfies config[r] = r.
    • config[n..2n] = bijection: config[n+v] is the tree node f(v) assigned to vertex v.
  • Meaning: A satisfying assignment is a (tree, mapping) pair such that (1) the parent array forms a valid rooted tree, (2) the bijection is a valid permutation, (3) for every graph edge {u,v}, f(u) and f(v) are in an ancestor-descendant relationship in T, and (4) the total tree distance sum_{{u,v} in E} d(f(u), f(v)) <= K.

Schema (data type)

Type name: RootedTreeArrangement
Variants: graph topology (graph type parameter G)

Field Type Description
graph SimpleGraph The undirected graph G = (V, E) to be arranged in a tree
bound usize Maximum total distance K

Size fields:

  • num_vertices() — number of vertices |V|
  • num_edges() — number of edges |E|

Notes:

  • This is a satisfaction (decision) problem: Metric = bool, implementing SatisfactionProblem.
  • No weight type is needed; edge distances are measured in the tree (hop count).
  • The rooted tree T is part of the solution, not part of the instance.

Complexity

  • Best known exact algorithm: No specialized exact algorithm is known. Brute-force enumerates all rooted labeled trees on n nodes (n^(n-1) by Cayley's formula) and all n! bijections, checking the ancestral path constraint and distance bound. With the parent-array encoding, the configuration space is n^(2n).
  • Complexity string for declare_variants!: "2^num_vertices" (conservative NP-complete bound, matching OptimalLinearArrangement convention).
  • Special cases: For trees (G is a tree), the problem can be solved in polynomial time. Adolphson and Hu (1973) gave an O(n log n) algorithm for optimal linear arrangement of trees, and similar techniques apply.
  • NP-completeness: NP-complete [Gavril, 1977a], via reduction from OPTIMAL LINEAR ARRANGEMENT (GT43).
  • References:
    • F. Gavril (1977). "Some NP-complete problems on graphs." In: Proceedings of the 11th Conference on Information Sciences and Systems, pp. 91-95. Johns Hopkins University.
    • M. R. Garey, D. S. Johnson, and L. Stockmeyer (1976). "Some simplified NP-complete graph problems." Theoretical Computer Science 1(3):237-267.
    • D. Adolphson and T. C. Hu (1973). "Optimal linear ordering." SIAM Journal on Applied Mathematics 25(3):403-423.

Extra Remark

Full book text:

INSTANCE: Graph G = (V,E), positive integer K.
QUESTION: Is there a rooted tree T = (U,F), with |U| = |V|, and a one-to-one function f: V -> U such that for every edge {u,v} in E there is a simple path from the root that includes both f(u) and f(v) and such that if d(x,y) is the number of edges on the path from x to y in T, then sum_{{u,v} in E} d(f(u),f(v)) <= K?

Reference: [Gavril, 1977a]. Transformation from OPTIMAL LINEAR ARRANGEMENT.

How to solve

  • It can be solved by (existing) bruteforce — the parent-array + permutation encoding maps directly to the Problem trait: dims() = vec![n; 2*n] enumerates all (parent array, bijection) pairs. evaluate() checks (1) valid rooted tree, (2) valid permutation, (3) ancestral path constraint, and (4) distance bound. Most configurations are invalid (not a tree or not a permutation), but BruteForce filters these naturally via evaluate() = false.
  • It can be solved by reducing to integer programming.
  • Other: For special graph classes (paths, trees), polynomial-time algorithms exist. For general graphs, the problem is NP-complete.

Example Instance

Instance 1 (YES, path graph can be arranged tightly):
Graph G with 6 vertices {0, 1, 2, 3, 4, 5} and 5 edges:

  • Edges: {0,1}, {1,2}, {2,3}, {3,4}, {4,5}
  • (Simple path P_6)
  • Bound K = 5.

Solution: Use rooted tree T as a chain 0 -> 1 -> 2 -> 3 -> 4 -> 5 (rooted at 0), with identity mapping f(v) = v.

  • Each edge {i, i+1} has d(i, i+1) = 1 in T.
  • Total distance = 5 * 1 = 5 <= K = 5. ✓
  • Each pair f(i), f(i+1) lies on the root-to-leaf path 0->1->2->3->4->5. ✓
  • Answer: YES

Instance 2 (YES, triangle + path forces chain):
Graph G with 5 vertices {0, 1, 2, 3, 4} and 5 edges:

  • Edges: {0,1}, {0,2}, {1,2}, {2,3}, {3,4}
  • (Triangle 0-1-2 plus path 2-3-4)
  • Bound K = 7.

The triangle {0,1,2} forces all three vertices onto a single root-to-leaf path (each pair must be in ancestor-descendant relationship). Combined with edges {2,3} and {3,4}, all 5 vertices must lie on a single chain.

Solution: Chain tree 0 -> 1 -> 2 -> 3 -> 4 (rooted at 0), identity mapping f(v) = v.

  • d(0,1) = 1, d(0,2) = 2, d(1,2) = 1, d(2,3) = 1, d(3,4) = 1
  • Total = 1 + 2 + 1 + 1 + 1 = 6 <= K = 7. ✓
  • All edges connect ancestor-descendant pairs. ✓
  • Answer: YES

Suboptimal feasible arrangement [0, 2, 1, 3, 4] (swap vertices 1 and 2):

  • d(0,1) = |0-2| = 2, d(0,2) = |0-1| = 1, d(1,2) = |2-1| = 1, d(2,3) = |1-3| = 2, d(3,4) = |3-4| = 1
  • Total = 2 + 1 + 1 + 2 + 1 = 7 <= K = 7. ✓ (suboptimal but feasible)

Infeasible arrangement [2, 1, 0, 3, 4]:

  • d(0,1) = |2-1| = 1, d(0,2) = |2-0| = 2, d(1,2) = |1-0| = 1, d(2,3) = |0-3| = 3, d(3,4) = |3-4| = 1
  • Total = 1 + 2 + 1 + 3 + 1 = 8 > K = 7. ✗

Instance 3 (NO, triangle needs chain):
Graph G with 6 vertices {0, 1, 2, 3, 4, 5} and 7 edges forming two triangles connected by a path:

  • Edges: {0,1}, {1,2}, {0,2}, {2,3}, {3,4}, {4,5}, {3,5}
  • Bound K = 8.

In any rooted tree, the triangle {0,1,2} forces all three vertices onto a single root-to-leaf path, costing at least d(0,1) + d(1,2) + d(0,2) >= 1 + 1 + 2 = 4. Similarly {3,4,5} with edge {3,5} forces a chain costing at least 4. Plus edge {2,3} costs at least 1. Minimum total >= 4 + 4 + 1 = 9 > K = 8. Answer: NO.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoodAn issue passed all checks.modelA model problem to be implemented.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions