# Examples

> See Knotkit modules work together on routing, search, streaming, and optimization problems.

Find a route across a real road network, detect near-duplicate documents, or compact sorted runs in an LSM tree. Open an example to see how the modules fit together, what the baseline does, and how to rerun the comparison.

Filter 21 examples…ModuleEvery module (all)

[![](/figures/problems/bit-width-allocation/allocation-quality-and-time.png)](/problems/bit-width-allocation/)

### [Bit-width allocation](/problems/bit-width-allocation/)

At nine layers, dynamic programming matches exhaustive loss in 0.0714 ms against 3.6329 ms

* [prng](/modules/prng/)
* [errors](/modules/errors/)

[![](/figures/problems/budget-allocation/reach-and-time.png)](/problems/budget-allocation/)

### [Budget allocation](/problems/budget-allocation/)

Lazy greedy needs 576 gain evaluations against full-scan greedy's 22,500 at budget 75 on low-overlap (0.267 ms against 4.274 ms)

* [heap](/modules/heap/)
* [prng](/modules/prng/)
* [graph](/modules/graph/)
* [sampling](/modules/sampling/)

[![](/figures/problems/context-selection/evidence-packing.png)](/problems/context-selection/)

### [Context selection](/problems/context-selection/)

Packing three search hits into 21 words: new-query-terms-first keeps the setup rule and the version caveat in 19 words, where rank-and-truncate drops the caveat

* [deque](/modules/deque/)
* [heap](/modules/heap/)
* [sampling](/modules/sampling/)
* [prng](/modules/prng/)

[diverse-subset-selection](/problems/diverse-subset-selection/)

### [Diverse subset selection](/problems/diverse-subset-selection/)

On a 384-result pool, greedy determinant selection covers 8.00 topics at size 8, against 1.00 for top-quality selection

* [errors](/modules/errors/)

[![](/figures/problems/live-variables/block-evaluations.png)](/problems/live-variables/)

### [Live variables](/problems/live-variables/)

A backward worklist saves 510 of 768 block evaluations on a 256-block control-flow graph

* [graph](/modules/graph/)
* [bitset](/modules/bitset/)
* [deque](/modules/deque/)

[![](/figures/problems/lsm-compaction/update-heavy.png)](/problems/lsm-compaction/)

### [LSM compaction](/problems/lsm-compaction/)

On the skewed trace at fanout 4, size-tiered writes 1.81× input bytes and searches 2.70 runs per point lookup; full-level writes 2.24× and searches 1.97

* [heap](/modules/heap/)
* [interval-index](/modules/interval-index/)
* [ordered-map](/modules/ordered-map/)
* [prng](/modules/prng/)
* [scalar-sketch](/modules/scalar-sketch/)
* [sorted-block](/modules/sorted-block/)
* [sorted-merge](/modules/sorted-merge/)
* [static-filter](/modules/static-filter/)

[![](/figures/problems/metric-tsp/distance-and-time.png)](/problems/metric-tsp/)

### [Metric TSP](/problems/metric-tsp/)

MST walk at n = 442: the three graph layouts land within 5% (0.697–0.723 ms); Held-Karp solves burma14 in 2.61 ms

* [graph](/modules/graph/)
* [distance](/modules/distance/)
* [prng](/modules/prng/)

[![](/figures/problems/min-cut/trial-bounds.png)](/problems/min-cut/)

### [Minimum cut](/problems/min-cut/)

Classic contraction on a 75-vertex graph: indexed layout 0.0251 ms against 0.0393 ms for object

* [disjoint-set](/modules/disjoint-set/)
* [prng](/modules/prng/)

[![](/figures/problems/mst/comparisons-per-edge.png)](/problems/mst/)

### [Minimum spanning tree](/problems/mst/)

At 100,000 vertices, Kruskal over indexed takes 31.31 ms against 46.58 ms for object; Prim with k=4 takes 106.11 ms against 116.08 ms for binary

* [heap](/modules/heap/)
* [disjoint-set](/modules/disjoint-set/)
* [prng](/modules/prng/)

[![](/figures/problems/near-duplicate-detection/banding-tradeoff.png)](/problems/near-duplicate-detection/)

### [Near-duplicate detection](/problems/near-duplicate-detection/)

On a pinned 400-document corpus, 16 bands of 4 score 77 of 79,800 possible pairs and recover all 62 pairs above 0.6

* [scalar-sketch](/modules/scalar-sketch/)
* [inverted-index](/modules/inverted-index/)
* [disjoint-set](/modules/disjoint-set/)
* [distance](/modules/distance/)

[![](/figures/problems/nearest-neighbors/sift10k-recall-latency.png)](/problems/nearest-neighbors/)

### [Nearest neighbors](/problems/nearest-neighbors/)

On SIFT10K, HNSW at width 32 reaches 99.4% held-out recall\@10 at 0.21 ms p95, against 1.5 ms for exhaustive search

* [inverted-index](/modules/inverted-index/)
* [heap](/modules/heap/)
* [bitset](/modules/bitset/)
* [cache](/modules/cache/)
* [distance](/modules/distance/)
* [prng](/modules/prng/)
* [sampling](/modules/sampling/)

[![](/figures/problems/notification-replay/delivery-cap.png)](/problems/notification-replay/)

### [Notification replay](/problems/notification-replay/)

With 100 ranges, summaries approve 16 of 32 replays and cost a mean 43,200 bytes, against 80,000 to fetch both count arrays

* [frequency-table](/modules/frequency-table/)
* [inverted-index](/modules/inverted-index/)

[per-client-rate-limit](/problems/per-client-rate-limit/)

### [Per-client rate limit](/problems/per-client-rate-limit/)

On a 7,510-arrival trace the bounded table keeps 64 clients in at most 170 KB; the hand-written Map counter keeps 4,146 in 684 KB

* [rate-limit](/modules/rate-limit/)

[![](/figures/problems/quantized-dot-product/four-weights-one-byte.png)](/problems/quantized-dot-product/)

### [Quantized dot product](/problems/quantized-dot-product/)

Scoring 65,539 two-bit weights took 64.7 µs directly from packed bytes and 162.6 µs with per-call expansion

* [prng](/modules/prng/)
* [errors](/modules/errors/)

[![](/figures/problems/read-clustering/posting-lengths.png)](/problems/read-clustering/)

### [Read clustering](/problems/read-clustering/)

inline-singleton clusters in 300.1 ms and retains 5,367,998 bytes per index; map-of-sets takes 322.5 ms and retains 26,328,798

* [inverted-index](/modules/inverted-index/)
* [deque](/modules/deque/)

[![](/figures/problems/road-network/rome-shortest-path.png)](/problems/road-network/)

### [Road network routing](/problems/road-network/)

On the New York network, dijkstra from one source takes 79.0 ms on compressed-sparse-row against 27.1 ms hand-written (2.7–3.3× on search rows)

* [graph](/modules/graph/)
* [heap](/modules/heap/)

[![](/figures/problems/sliding-window-median/rolling-median.png)](/problems/sliding-window-median/)

### [Sliding-window median](/problems/sliding-window-median/)

Random input at width 128: sorting each window takes 147.19 ms, a sorted array 4.04 ms, an indexed skip list 9.48 ms

* [frequency-table](/modules/frequency-table/)
* [ordered-map](/modules/ordered-map/)

[![](/figures/problems/sliding-window-minimum/minimum-comparisons.png)](/problems/sliding-window-minimum/)

### [Sliding-window minimum](/problems/sliding-window-minimum/)

Increasing input at width 128: the array deque takes about 0.48 ms against 8.36 ms for rescanning; on random input rescanning is faster

* [deque](/modules/deque/)

[![](/figures/problems/speculative-decoding/draft-acceptance.png)](/problems/speculative-decoding/)

### [Speculative decoding](/problems/speculative-decoding/)

39.1% paired-latency reduction on one NVIDIA A10 for a 260K-parameter toy target and a zero-cost n-gram draft; Qwen 0.5B/1.5B was 37.4% slower

* [distribution](/modules/distribution/)
* [prng](/modules/prng/)

[![](/figures/problems/tsp/tour-convergence.png)](/problems/tsp/)

### [Traveling salesperson](/problems/tsp/)

Bounded complete runs: sim-grid-B-010 in 2.784 ms and sim-grid-B-050 in 6.947 ms; policy rows are too noisy to rank

* [evolution](/modules/evolution/)
* [sampling](/modules/sampling/)
* [distance](/modules/distance/)
* [prng](/modules/prng/)

[![](/figures/problems/word-ladder/word-ladder-distances.png)](/problems/word-ladder/)

### [Word ladder](/problems/word-ladder/)

16 shortest ladders take 0.79 ms on compressed-sparse-row against 14.12 ms on the implicit graph; packed postings retain 96.8% less memory

* [graph](/modules/graph/)
* [inverted-index](/modules/inverted-index/)

No example matches. [Find a module by task](/choosing/) instead.

## Run one yourself

```bash
git clone https://github.com/jkomyno/knotkit.git && cd knotkit
bun install
bun run demo:problem:near-duplicate-detection
```

Results come from one machine. Expect different absolute numbers on yours.
