KMP Failure Function (π-Prefix Array) Synthesizer
Deterministic preprocessor computing the longest proper prefix that is also a suffix for all pattern prefixes P[0..q] in O(m) time.
To investigate the theoretical foundations and microarchitectural mechanics of exact string matching algorithms, evaluate the Knuth-Morris-Pratt (KMP) prefix function π-array, contrast KMP with Boyer-Moore sublinear shift heuristics and Rabin-Karp rolling hashes, and empirically verify the linear comparison scaling law C(n) = k_kmp · n + C_0 = 1.0000 · n + 20.0000 comparisons across text stream lengths n ∈ [500, 10000] characters for pattern length m = 20. Explore interactive search algorithms, compare operation counts and analyse complexity scaling.
Ready to execute text length benchmark.
Adjust text length n, then execute benchmark.
Operation counts are generated deterministically by the exact algorithmic execution model. Modern hardware benchmarks additionally reflect cache line prefetching and branch misprediction penalties.
The simulated execution environment models idealized scalar CPU comparison registers where every character equality evaluation executes with deterministic cost of 1 operation (C(n) = n + m). In physical semiconductor microprocessors, wall-clock execution latency is modulated by CPU L1 data cache hit ratios during text buffer streaming, hardware branch predictor mispredictions during character mismatch redirects (`if (P[j] == T[i])`), Translation Lookaside Buffer (TLB) page table walks across large corpus buffers, and hardware SIMD vector unit availability. In the Knuth-Morris-Pratt (KMP) text search benchmark with pattern length m = 20, the algorithm executes in two distinct phases: (1) Preprocessing the failure function π[0 .. m-1], which consumes exactly C_0 = m = 20 comparisons; and (2) Scanning the text stream T[0 .. n-1], where the text pointer i strictly advances from 0 to n - 1. Because the text pointer never moves backward and pattern pointer fallback via π[j-1] is bounded by prior increments, the scanning phase executes with an empirical scaling rate of exactly k_kmp = 1.0000 comparison per text character on uniform corpus data. Total character comparisons scale strictly as C(n) = 1.0000 · n + 20.0000 comparisons, yielding an exact linear relationship with zero residual variance across all benchmark trials.
Deterministic preprocessor computing the longest proper prefix that is also a suffix for all pattern prefixes P[0..q] in O(m) time.
Dual-heuristic jump tables calculating right-to-left shift vectors based on mismatch character identity and matching suffix patterns.
Hardware polynomial hash accumulator evaluating rolling substring signatures modulo large prime q using Horner's method.
Automaton compiler constructing trie hierarchies, failure transitions, and dictionary output links for simultaneous multi-string scanning.
Microarchitectural vector execution register executing 64-byte parallel character comparisons via byte-mask instructions.
Configurable text stream synthesizer generating controlled alphabets, natural language corpora, and pathological repeated-prefix sequences.
To investigate the theoretical foundations and microarchitectural mechanics of exact string matching algorithms, evaluate the Knuth-Morris-Pratt (KMP) prefix function π-array, contrast KMP with Boyer-Moore sublinear shift heuristics and Rabin-Karp rolling hashes, and empirically verify the linear comparison scaling law C(n) = k_kmp · n + C_0 = 1.0000 · n + 20.0000 comparisons across text stream lengths n ∈ [500, 10000] characters for pattern length m = 20. Suggested independent settings: 500, 1000, 2000, 4000, 6000, 8000, 10000 chars.
Load the target pattern P[0 .. 19] of length m = 20 characters. Execute the failure function preprocessor to compute π[0 .. 19], logging exactly C_0 = 20 preprocessing comparison operations into the telemetry register.
Adjust the independent variable control slider to configure the input text stream length n between 200 and 10,000 characters across the designated benchmark sample points.
Trigger the KMP matching engine. Traverse text pointer i from 0 to n-1, comparing text character T[i] with pattern character P[j]. On match, advance j; on mismatch, redirect j to π[j-1] without decrementing text pointer i.
Read the total character comparison count C(n) from the algorithmic comparator register upon stream completion, verifying that C(n) = n + m comparisons.
Log the independent text length n and dependent comparison count C(n) into the laboratory notebook table and plot the corresponding data coordinate.
Perform ordinary least-squares regression across all seven benchmark trials to extract the text scan slope k_kmp and intercept C_0, evaluating residual variance, cache throughput, and comparative algorithm trade-offs.
Points are your recorded benchmark observations. The regression line validates String Matching & KMP Automata complexity scaling.
| # | Text length n characters (pattern length m = 20) (chars) | KMP character comparisons C(n) (comparisons) | Text stream length n (characters) | KMP character comparisons C(n) = n + m (comparisons) | Remove |
|---|
No readings yet. Execute a text length benchmark and record it.