---
title: PC-tree Data-Structure
url: https://www.emergentmind.com/topics/pc-tree-data-structure
type: topic
---

# PC-tree Data-Structure

A PC-tree is an undirected tree-based data structure that encodes sets of circular orders on a finite ground set $L$, subject to constraints that designated subsets of $L$ must appear consecutively. By construction, a PC-tree $T$ is formed from leaf nodes, which are bijectively mapped to elements of $L$, and inner nodes, which may be P-nodes (permutable) or C-nodes (circular). Consecutivity constraints are enforced via a single uniform update procedure, endowing the PC-tree with both conceptual simplicity and practical efficiency in comparison to PQ-trees, which encode linear orders and require more intricate update logic. PC-trees are predominantly utilized in planarity testing and related applications.

## 1. Structure and Formal Definition

Let $L$ be a finite ground set, interpreted as the token set whose circular orderings are represented by the PC-tree. The PC-tree $T$ satisfies the following structural constraints:

- **No inner node has degree 2**; such nodes are implicitly contracted.
- **Inner nodes** are partitioned as follows:
  - **P-nodes**, for which the cyclic order of the incident edges may be permuted arbitrarily.
  - **C-nodes**, for which incident edges are arranged in a cyclic order that may only be globally reversed.
- **Leaves** are in bijective correspondence with $L$.

Given a selection, for each P-node, of a permutation of its incident edges, and for each C-node, a choice between its cyclic order and its reverse, one obtains a circular permutation of $L$ by reading off the leaf labels in a boundary walk. The set of all such circular permutations is denoted $\Pi(T)$. Any transformation that replaces $T$ with $T'$ and preserves $\Pi(T) = \Pi(T')$ is valid. Under update operations, $T$ remains a PC-tree, and the invariants described above are preserved [2106.14805].

## 2. Node Types and Representation of Circular Orders

Each node type in the PC-tree structure serves a distinct role in encoding the constraint space:

- **Leaves**: Each corresponds bijectively to an element of $L$.
- **P-nodes**: Allow full permutation of their neighboring subtrees, encoding unconstrained groupings.
- **C-nodes**: Enforce a cyclic grouping, restricting rearrangement to only a global reversal of the order of attached subtrees.

Reordering leaves at P-nodes and reversing the cyclic order at C-nodes enable the PC-tree to generate all valid circular orders of $L$ consistent with the imposed consecutivity constraints [2106.14805].

## 3. Update Algorithm: Enforcing Consecutivity Constraints

The principal operation on a PC-tree is to update the tree so that a subset $R \subseteq L$ appears consecutively in every represented circular order. This is accomplished by the `Update(T, R)` algorithm, which follows these steps:

1. **Labeling**: Each node is labeled as full (all but at most one neighbor are full), empty (similarly, all but one are empty), or partial (otherwise).
2. **Terminal Path Discovery**: Identify the unique path of terminal edges (those separating subtrees containing at least one full versus empty leaf) with endpoints $t_1$ and $t_2$.
3. **Reordering/Flipping**: Along the terminal path, for each P-node, permute incident edges to make full neighbors contiguous; for each C-node, reverse the cyclic order if necessary.
4. **Splitting**: Each node on the terminal path is split into "full" and "empty" nodes, partitioning incident edges.
5. **Central C-node Insertion**: Remove terminal path edges and insert a new central C-node that reconnects the split nodes in a cyclic order.
6. **Contraction and Merging**: Merge adjacent C-nodes, contract degree-2 inner nodes to maintain invariants [2106.14805].

Each update executes in $O(p + |R|)$ time, where $p$ is the length of the terminal path, and $|R|$ is the size of the restricted set. Applying $k$ restrictions $R_1, \ldots, R_k$ takes $\Theta(|L| + \sum|R_i|)$ time overall.

## 4. Implementation Techniques

Two principal implementation paradigms are recognized:

### Hsu & McConnell Template-Based (HsuPC)

- Utilizes a circular doubly-linked list of half-edges (arcs) around each C-node.
- No explicit C-node objects; C-nodes are implicitly represented by the boundaries of their arcs.
- Block-spanning pointers enable merging of contiguous full blocks in $O(1)$.
- Full/partial detection, reordering, splitting, and merging as per the canonical update.
- Optimizations include timestamps on nodes to avoid costly tree traversals and refined handling of root cases [2106.14805].

### Union-Find Based (UFPC)

- Each C-node is an explicit entry in a Union-Find structure, and incident child pointers reference this entry.
- Merging C-nodes is delegated to union operations, facilitating efficient identity management.
- The tree is stored as a classic child-sibling doubly-linked structure, minimizing pointer-chasing overhead.
- Parent lookup is amortized $O(\alpha(|L|))$, yielding an overall update time of $O((p + |R|)\alpha(|L|))$, with superior cache locality leading to substantially faster practical performance [2106.14805].

## 5. Empirical Evaluation and Performance Analysis

Experimental comparisons utilized test suites such as SER-POS (possible restrictions, $n \in [1000, 20000]$, $|R| \in [5, |L| - 2]$), SER-IMP (impossible restrictions from non-planar cases), and DIR-PLAN (planarity test restrictions, up to $n = 10^6$, $|R| \geq 25$). Implementations compared included HsuPC, UFPC, the OGDF PQ-tree, and other publicly available PQ- and PQR-tree solvers.

Results demonstrated:

- Both PC-tree implementations (HsuPC, UFPC) run in time linear in $|R|$—independent of $|L|$—whereas some PQ implementations exhibit $|L|$-dependent scaling.
- On DIR-PLAN, median update-time ratios (relative to OGDF) were: HsuPC ~0.45 ($\approx2\times$ speedup), UFPC ~0.25 ($\approx4\times$ speedup).
- UFPC outperforms HsuPC for larger restrictions and longer terminal paths (for $p \geq 10$).
- Table:

| Implementation         | Speedup vs. OGDF |
|------------------------|------------------|
| HsuPC (PC-tree)        |    2.2×         |
| UFPC (PC-tree)         |    4.1×         |
| OGDF (PQ-tree)         |    1.0×         |
| Gregable (PQ-tree)     |    1.8×         |

[2106.14805]

## 6. Comparison with PQ-Trees

PC-trees and PQ-trees represent equivalent abstract constraints but differ in design and operational complexity:

- **Update Mechanisms**: PC-trees use a single split+merge update, while PQ-trees require nine template-driven case analyses with recursive matching.
- **Implementation Burden**: PC-trees avoid complex recursion and case distinctions but require careful handling of the central C-node and immediate contraction/merging to maintain invariants.
- **Asymptotic Runtime**: Both are theoretically linear in $|L| + \sum|R_i|$; PC-trees offer smaller constant factors.
- **Empirical Performance**: State-of-the-art PC-tree implementations (notably UFPC) are $3$–$4\times$ faster than leading PQ-tree packages in large-scale benchmarks [2106.14805].

## 7. Practical Implementation Guidelines

Guidance for effective PC-tree engineering includes:

- Employ timestamps or generation counters to prevent redundant post-update clean-up traversals.
- When adopting the Hsu & McConnell approach, maintain block-spanning pointers for $O(1)$ merging of full blocks around C-nodes.
- For Union-Find-based approaches, use explicit C-node objects for identity and unification.
- Store the tree using child-sibling doubly-linked lists to economize on pointer management and enhance cache coherence.
- Pay particular attention to root node edge cases in labeling and terminal path computation.
- Check for impossible restrictions early (flagging nodes with $>2$ terminal edges or conflicting apexes).
- After central C-node insertion, immediately contract all degree-2 inner nodes and merge adjacent C-nodes to uphold invariants.
- Rigorously test on sequences from planarity testing, both feasible and infeasible, to validate correctness.
- Profile performance on synthetic random planar graphs to optimize low-level data layout and pointer management for target hardware [2106.14805].

Source: https://www.emergentmind.com/topics/pc-tree-data-structure