Computer Science / Tries & Radix Prefix Trees
FREE TO EXPLORE
LABORATORY 15 · COMPUTER SCIENCE

Tries & Radix Prefix Trees lab report

A worked tries & radix prefix trees lab report with benchmark data tables, asymptotic graphs, calculations, uncertainty and conclusions.

WORKED EXAMPLE · BENCHMARK OBSERVATIONS

A complete example laboratory report.

Simulated demonstration data.

This report illustrates formal algorithmic benchmarking, operation counting arithmetic, and regression analysis. Replace its observations with your own benchmark telemetry when preparing a practical submission.

Student: __________________Student ID: __________________Course: __________________Date: __________________Partner: __________________Instructor: __________________

1. Title and aim

Empirical Analysis of Trie Architectures: Standard Tries, Compressed Radix Trees (Patricia Tries), Ternary Search Trees (TST), Longest Prefix Matching (LPM), and Key Retrieval Asymptotics. To investigate the architectural design and microarchitectural performance of Prefix Tree structures, evaluate Standard Tries against Compressed Radix Trees (Patricia Tries) and Ternary Search Trees (TST), examine Longest Prefix Matching (LPM) in IP network routing tables, and empirically verify the linear retrieval scaling law T(L) = k_trie · L + T_0 = 1.0000 · L + 1.0000 pointer dereferences across search key lengths L ∈ [4, 48] characters.

2. Abstract

Seven benchmark trials were generated across prefix search key lengths L = 4 to L = 48 characters (total pointer dereferences T from 5 to 49 operations). An ordinary least-squares regression of trie pointer dereferences against query key length yielded an empirical traversal slope of 1.0000 dereferences/char and an intercept of 1.0000 dereferences, demonstrating exact agreement with the theoretical trie retrieval complexity model T(L) = L + 1 (difference = 0.0000%). The empirical telemetry confirms that trie lookup latency is strictly invariant to the total number of dictionary keys n, scaling in direct linear proportion to key length L while supporting prefix autocompletion, wildcard searching, and longest prefix matching.

3. Apparatus and fixed settings

4. Theory and graph choice

The Trie—an information reTRIEval tree structure invented by René de la Briandais in 1959 and Edward Fredkin in 1960—represents a foundational paradigm shift in data structure design. Unlike comparison-based search trees (such as Binary Search Trees, AVL, and Red-Black trees) which treat search keys as atomic, indivisible entities and require Θ(log n) key comparisons, a Trie decomposes search keys into discrete sequential character symbols or bit chunks. In a rooted multi-way trie over alphabet Σ, the root represents the empty prefix ϵ, and each node branches into up to |Σ| child pointers corresponding to subsequent alphabet characters. Crucially, the key associated with a node is not stored explicitly within the node itself; rather, it is defined implicitly by the path from the root to that node. Consequently, searching for a key of length L characters requires walking exactly L child pointer dereferences—a retrieval cost strictly bounded by O(L), completely invariant to the total number of keys n stored in the dictionary! While standard multi-way tries provide optimal O(L) lookup times and seamless prefix autocomplete queries, naive implementations suffer from severe memory inflation: if each node allocates an array of 256 64-bit pointers (2,048 bytes per node), millions of sparse nodes waste physical memory. To conquer this memory tax, Donald R. Morrison (1968) formulated the Patricia Trie (Practical Algorithm to Retrieve Information Coded in Alphanumeric), also known as the Compressed Radix Tree. Patricia tries eliminate all single-child non-branching nodes, collapsing linear edge sequences into composite substring labels, guaranteeing that a tree containing n keys has at most 2n - 1 total nodes! Symmetrically, Jon Bentley and Robert Sedgewick (1997) invented Ternary Search Trees (TST), replacing 256-way pointer arrays with balanced three-way branching nodes (left, equal, right), combining the spatial efficiency of binary trees with the prefix retrieval speed of tries. In computer networking, Internet core routers utilize multi-stride radix tries to perform Longest Prefix Matching (LPM) over CIDR IPv4/IPv6 routing tables at wire speed (>400 Gbps). In this laboratory investigation, students benchmark trie traversal latencies across key lengths L ∈ [4, 48], verify the exact linear scaling law T(L) = 1.0000 · L + 1.0000 pointer dereferences via ordinary least-squares regression, contrast path compression mechanisms, and analyze cache line locality in modern Adaptive Radix Trees (ART).

T(L) = k_trie · L + T_0 = 1.0000 · L + 1.0000 dereferences

The mathematical regression fits the linear model y = mx + b, where x = L represents the search key length in characters, y = T represents total pointer dereference operations, m represents the traversal slope k_trie, and b represents the root sentinel node dereference overhead (theoretically T_0 = 1.0000 dereferences). The gradient has physical units dereferences/char.

5. Method

  1. Allocate the trie root node, clearing all 64 child pointer entries to NULL and initializing the root sentinel dereference baseline T_0 = 1 operation.
  2. Adjust the independent variable control slider to choose a search key length L between 4 and 64 characters across the designated benchmark sample points.
  3. Trigger the synthetic generator to load a 10,000-key dictionary into the trie and synthesize a deterministic target query string of length L.
  4. Traverse the trie from root to leaf, resolving characters sequentially from index 0 to L-1. For each character, dereference the corresponding child pointer.
  5. Read the total pointer dereference count T(L) from the memory access monitor upon locating the terminal node, verifying that T(L) = L + 1 dereferences.
  6. Record total dereferences across all seven benchmark trials. Regress T(L) against key length L to compute slope k_trie, intercept T_0, and coefficient of determination R².

6. Observations and calculation table

All benchmark observations use strictly controlled memory buffers. Values are recorded deterministically from the algorithmic comparator register. Residuals are computed relative to the ordinary least-squares regression line.

Table 1. Seven simulated algorithmic benchmarks; x and y represent computational state metrics.
No.Prefix search key length L (characters / bits) (chars)Trie path pointer dereferences T(L) (dereferences)Prefix search key length L (characters)Trie pointer dereferences T(L) = L + 1 (dereferences)Fitted yResidual
1454.00005.00005.00000.0000
2898.00009.00009.00000.0000
3121312.000013.000013.00000.0000
4161716.000017.000017.00000.0000
5242524.000025.000025.00000.0000
6323332.000033.000033.00000.0000
7484948.000049.000049.00000.0000

Download the sample observations (CSV) ↓

7. Worked calculation for one observation

Query Prefix Key Length L = 4 characters; Root Sentinel Node = 1 dereference; Internal Edge Transitions = 4 child dereferences. Total Path Pointer Dereferences: T(L) = k_trie · L + T_0 = 1.0000 × 4 + 1 = 5 dereferences. Verification: Traversal initiates at the root sentinel node (consuming 1 initial pointer inspection) and sequentially dereferences exactly one child pointer for each character in the query string from index 0 to 3, concluding in strictly L + 1 = 4 + 1 = 5 dereferences.

8. Graph, gradient and final calculation

-1.60-1.2812.7012.3627.0026.0041.3039.6455.6053.28Prefix search key length L (characters)Trie pointer dereferences T(L) = L + 1 (dereferences)n = 4n = 8n = 12n = 16n = 24n = 32n = 48

Circular markers represent empirical benchmark observations. The solid line represents the ordinary least-squares asymptotic linear fit.

x̄ = 20.57143; ȳ = 21.57143
Σ(x − x̄)² = 1421.71429
Σ(x − x̄)(y − ȳ) = 1421.71429
m = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² = 1.00000000
b = ȳ − mx̄ = 1.00000000
k_trie = m = 1.0000 dereferences/char; Intercept T_0 = 1.0000 dereferences (theoretical k_trie = 1.0000, T_0 = 1.0000)

9. Uncertainty and comparison

Percentage difference = |estimate − theoretical value| / |theoretical value| × 100 = 0.0000%.

For n = 7 benchmark observations, Σresidual² = 0.00000; s² = Σresidual²/(n − 2). Gradient standard error = √[s²/Σ(x − x̄)²] = 2.6521e-08. Intercept standard error = √[s²(1/n + x̄²/Σ(x − x̄)²)] = 6.6371e-07.

Propagating the fit parameters yields a fit standard error of 2.6521e-08 dereferences/char, with an ideal coefficient of determination R² = 1.000000.

In discrete data structure analysis, the trie pointer dereference count T(L) = k_trie · L + T_0 = 1.0000·L + 1.0000 for standard prefix tree traversal is an exact deterministic invariant across key length L. Unlike continuous physical instrumentation, there is no analog sensor noise, thermal drift, or calibration variance in counting discrete pointer dereferences or memory bus loads. However, in physical semiconductor microprocessors, wall-clock trie retrieval latency is strongly modulated by memory hierarchy and microarchitectural dynamics: (1) Pointer chasing cache line misses: because child nodes are dynamically allocated at non-contiguous heap memory locations, walking down a naive 256-way trie causes cold L1/L2 data cache stalls (~100–250 CPU cycles per DRAM access) once the trie footprint exceeds cache capacity; (2) Hardware spatial prefetcher failure: non-linear heap-allocated node links prevent CPU hardware stream prefetchers from predicting memory accesses, causing standard multi-way tries to suffer severe pointer-chasing latency compared to contiguous flat tables; (3) Node compaction and SIMD acceleration in Adaptive Radix Trees (ART): ART avoids sparse 256-pointer arrays by adapting node capacities (Node4, Node16, Node48, Node256) based on child density, utilizing SIMD vector instructions (_mm_cmpeq_epi8) on Node16 to evaluate 16 character keys in a single clock cycle with zero branch mispredictions; and (4) Path compression in Patricia Tries: collapsing single-child non-branching node chains into composite substring edges reduces total node traversals by 50% to 80% on sparse key distributions, keeping high-frequency routing prefixes resident in L1/L2 caches. Ordinary least-squares linear regression of observed pointer dereferences against key length L across queries from 4 to 48 characters yields an empirical scaling slope k_trie = 1.0000 dereferences/char and intercept T_0 = 1.0000 dereferences with zero residual variance (R² = 1.00000), verifying the linear retrieval bound Θ(L) with mathematical certitude.

10. Result and discussion

k_trie = 1.0000 dereferences/char
Theoretical reference value: 1.0000 dereferences/char

The empirical benchmark observations provide rigorous quantitative verification of the Trie prefix tree architecture and asymptotic retrieval complexity. In a standard multi-way trie over alphabet Σ, the search algorithm begins at the root sentinel node (consuming 1 initial pointer inspection) and sequentially dereferences the child pointer corresponding to each character in the query key of length L. Because each character transition advances down the trie hierarchy by exactly one level, the traversal executes exactly L child dereferences, yielding total memory operations T(L) = 1.0000·L + 1.0000. Across all benchmark key lengths from L = 4 to L = 48 characters, the regression slope m = 1.0000 and intercept b = 1.0000 confirm this invariant with zero residual variance (R² = 1.00000). Crucially, the total number of keys n stored in the dictionary has zero effect on lookup depth, distinguishing tries from comparison-based binary search trees which scale as O(L · log n). Comparative architectural analysis elucidates vital engineering trade-offs across prefix tree representations: Standard multi-way tries provide optimal O(L) lookup times but suffer extreme spatial memory inflation when allocating 256 child pointers per node (2,048 bytes) on sparse vocabularies. Compressed Radix Trees (Patricia Tries) solve this by eliminating unbranched single-child nodes, collapsing linear edge sequences into composite substring labels, guaranteeing at most 2n - 1 nodes for n keys. Ternary Search Trees (TST) combine the space efficiency of binary search trees with the prefix properties of tries, branching three ways (left, equal, right) to reduce memory to 3 pointers per node at the cost of O(L + log |Σ|) lookup latency. In telecommunications and IP networking, multi-stride radix tries execute Longest Prefix Matching (LPM) over 32-bit IPv4 and 128-bit IPv6 CIDR forwarding tables, enabling core internet routers to forward packets at line speeds exceeding 400 Gbps. Finally, modern in-memory database engines employ Adaptive Radix Trees (ART), which dynamically resize nodes between 4 compact types (Node4, Node16, Node48, Node256) and use SIMD instructions to deliver both cache-conscious memory density and branch-free retrieval throughput.

11. Precautions and limitations

The simulated execution environment models idealized scalar CPU memory pointer dereferences where each node transition executes with deterministic cost of 1 operation (T(L) = L + 1). In physical semiconductor microprocessors, wall-clock retrieval latency is modulated by CPU L1/L2 data cache hit ratios during pointer chasing across dynamic heap nodes, Translation Lookaside Buffer (TLB) virtual memory page walks, hardware prefetcher limitations on branching structures, and memory bus bandwidth contention. In the Trie key retrieval benchmark across search key lengths L in [4, 48] characters, the retrieval algorithm starts at the root sentinel node (consuming 1 initial pointer inspection) and sequentially dereferences exactly one child pointer for each character in the query key. Because each character transition advances down the trie hierarchy by exactly 1 level, total memory pointer dereferences scale deterministically as T(L) = 1.0000 · L + 1.0000 dereferences with exact theoretical intercept T_0 = 1.0000 dereference. Ordinary least-squares regression across all benchmark trials yields an ideal coefficient of determination R² = 1.000000 with zero residual variance.

12. Conclusion

This laboratory investigation quantitatively verified the node structure, path compression mechanisms, and asymptotic retrieval scaling of Trie and Radix prefix trees. Through systematic benchmarking across query key lengths from L = 4 to 48 characters, we verified the empirical retrieval slope k_trie = 1.0000 dereferences/char and sentinel intercept T_0 = 1.0000 dereferences with an ideal R² = 1.00000. The investigation established the microarchitectural and algorithmic superiority of compressed radix trees and adaptive prefix tries over naive multi-way pointer arrays and comparison trees, proving why trie architectures serve as the backbone of modern IP routing, full-text search engines, lexical compilers, and high-performance key-value databases.