docs(docs): add strategy, coding, and system design documentation hierarchy

This commit is contained in:
Prad Nukala committed 2026-08-14 18:37:13 -04:00
1 parent 87581c4f4b
commit 91c45ea5de
70 files changed
+1343 -31

No files matched your search

@@ -0,0 +1,93 @@
---
title: 'Recognition'
description: 'There are only 6 structural families. Every pattern is a traversal or maintenance strategy over one of them.'
---
## Family 1 — Contiguous Linear (arrays, strings)
*Structure property: O(1) index access, order is information.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Two Pointers** (7) | Converging/parallel index walk that prunes the O(n²) pair space using order | Sorted input · pair/triplet with target · palindrome · in-place partition |
| **Sliding Window** (5) | Two pointers + incremental state between them (Two Pointers with a payload) | "Longest/shortest substring/subarray with property X" · contiguous constraint |
| **Prefix Sum** (2) | Precomputed cumulative state → O(1) range queries | "Sum of range" · "subarray sum equals K" · repeated interval aggregation |
| **Binary Search** (5) | Halving over ANY monotonic predicate — not just sorted arrays | Sorted/rotated input · "minimize the maximum" · answer space is monotonic (Koko) |
| **Matrices** (3) | 2D index arithmetic; often a graph in disguise | Grid traversal/rotation/spiral · if cells have neighbors → it's Family 5 |
**Systems anchor:** prefix sum is a materialized view; sliding window is stream processing with an eviction policy.
## Family 2 — Nodal Linear (linked lists)
*Structure property: O(1) splice, no random access. Everything is pointer surgery.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Linked List** (5) | Three moves cover it all: fast/slow runners, reversal, dummy-head splicing | Cycle detection · middle/Nth-from-end · reverse/reorder · merge |
**Systems anchor:** LRU Cache = hashmap + doubly-linked list — the one hybrid that appears constantly (it's a cache eviction index).
## Family 3 — Auxiliary Ordering Structures (stack, heap)
*Structure property: you don't traverse them — you maintain them while traversing something else.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Stack** (5) | LIFO memory of "unresolved" items; monotonic stack = discard dominated candidates | Matching/nesting (parens) · "next greater element" · "previous smaller" · expression eval |
| **Heap** (5) | Partial order — cheap access to extremum without full sort | "Kth largest/smallest" · "top K" · merge K streams · running median (two heaps) |
**Systems anchor:** monotonic stack ≈ log compaction (drop entries superseded by newer state); heap ≈ priority scheduling / Dijkstra's frontier / timer wheels.
## Family 4 — Hierarchical (trees, tries)
*Structure property: recursive shape — every node roots a subtree. Solutions are recurrences.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **DFS on trees** (part of 13) | Post/pre/in-order recursion; answer composed from subtree answers | "Max depth / diameter / LCA / validate" · anything defined recursively |
| **BFS on trees** (part of 8) | Level-order via queue | "Level by level" · "right side view" · minimum depth |
| **Trie** (2) | Character-indexed tree; shared prefixes = shared paths | Prefix search · autocomplete · word dictionaries · many-string matching |
| **BST specifically** | Sorted array in tree form — in-order traversal IS sorted order | "Kth smallest in BST" · range queries · validate |
**Systems anchor:** trie ≈ radix routing table / IPLD path resolution; BST invariant ≈ index B-tree.
## Family 5 — Relational (graphs)
*Structure property: arbitrary edges; must track visited. Trees are just acyclic connected graphs — same traversals, plus bookkeeping.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **DFS on graphs** (13) | Exhaustive reachability; recursion + visited set | Islands/regions/flood fill · connectivity · cycle detection (directed: 3-color) |
| **BFS on graphs** (8) | Frontier expansion → **shortest path in unweighted graphs, always** | "Minimum steps/moves" · multi-source spread (rotting oranges) · word ladder |
| **Graphs** (6): Topological sort | DFS post-order reversed / Kahn's in-degree queue over a DAG | Dependencies · prerequisites · build order · "valid ordering exists?" |
| **Graphs** (6): Union-Find | Incremental connectivity without traversal | Dynamic "same component?" queries · redundant edge · counting components |
**Systems anchor:** topo sort = dependency resolution (your Turborepo build graph); union-find = partition detection; BFS = gossip propagation. A matrix with neighbor-moves is ALWAYS this family, not Family 1.
## Family 6 — Decision-Space (implicit graphs you build while exploring)
*Structure property: nodes are STATES, not data. The structure doesn't exist until you walk it.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Backtracking** (6) | DFS over the state tree with undo; exhaustive enumeration | "All subsets/permutations/combinations" · constraint satisfaction · "generate all valid X" |
| **Dynamic Programming** (10) | Backtracking + memoization — overlapping subproblems collapse the exponential tree | "Count ways" · "min/max cost to reach" · choices with shared substructure · optimal substructure |
| **Greedy** (5) | DP where the local optimum provably suffices — no memo needed | Sort-then-commit works · exchange argument holds · intervals scheduling · jump game |
**Systems anchor:** DP memo = idempotency cache over a deterministic state machine; backtracking = saga with compensating undo; greedy = eventually-consistent local decisions that provably converge.
---
## The Recognition Decision Tree (run this in the first 2 minutes — rubric axis #1)
1. **Contiguous array/string, no neighbor semantics?** → Family 1. Sorted or monotonic answer space → Binary Search. Pair/window constraint → Two/Sliding. Range sums → Prefix.
2. **Nodes with next-pointers?** → Family 2. Reach for fast/slow or dummy-head before anything clever.
3. **Need "next greater," nesting, or top-K while scanning?** → Family 3 auxiliary structure on top of whatever you're traversing.
4. **Recursive shape (tree/prefix data)?** → Family 4. Ask: does the answer compose from subtrees (DFS) or from levels (BFS)?
5. **Arbitrary connections, grids with movement, dependencies?** → Family 5. Unweighted shortest = BFS. Ordering over DAG = topo. Dynamic connectivity = union-find. Otherwise DFS.
6. **Enumerate or optimize over CHOICES?** → Family 6. All solutions → backtracking. Overlapping subproblems → DP. Provable local choice → greedy.
## The Escalation Lattice (when stuck, patterns upgrade along these edges)
- Two Pointers —*add state*→ Sliding Window —*add aggregation*→ Prefix Sum
- Brute-force scan —*monotonic predicate*→ Binary Search on answer
- Tree DFS —*add visited set*→ Graph DFS —*add undo*→ Backtracking —*add memo*→ DP —*add proof*→ Greedy
- Sort —*need only extremum*→ Heap —*need running extremes*→ Monotonic Stack
- BFS —*add weights*→ Dijkstra (= BFS with a heap: Families 3+5 composed)
Memorize the lattice, not 16 patterns. In the interview, naming the family out loud ("this is a state-space problem, so backtracking or DP depending on overlap") IS the recognition signal the rubric scores.
@@ -0,0 +1,93 @@
---
title: 'Escalation'
description: 'There are only 6 structural families. Every pattern is a traversal or maintenance strategy over one of them.'
---
## Family 1 — Contiguous Linear (arrays, strings)
*Structure property: O(1) index access, order is information.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Two Pointers** (7) | Converging/parallel index walk that prunes the O(n²) pair space using order | Sorted input · pair/triplet with target · palindrome · in-place partition |
| **Sliding Window** (5) | Two pointers + incremental state between them (Two Pointers with a payload) | "Longest/shortest substring/subarray with property X" · contiguous constraint |
| **Prefix Sum** (2) | Precomputed cumulative state → O(1) range queries | "Sum of range" · "subarray sum equals K" · repeated interval aggregation |
| **Binary Search** (5) | Halving over ANY monotonic predicate — not just sorted arrays | Sorted/rotated input · "minimize the maximum" · answer space is monotonic (Koko) |
| **Matrices** (3) | 2D index arithmetic; often a graph in disguise | Grid traversal/rotation/spiral · if cells have neighbors → it's Family 5 |
**Systems anchor:** prefix sum is a materialized view; sliding window is stream processing with an eviction policy.
## Family 2 — Nodal Linear (linked lists)
*Structure property: O(1) splice, no random access. Everything is pointer surgery.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Linked List** (5) | Three moves cover it all: fast/slow runners, reversal, dummy-head splicing | Cycle detection · middle/Nth-from-end · reverse/reorder · merge |
**Systems anchor:** LRU Cache = hashmap + doubly-linked list — the one hybrid that appears constantly (it's a cache eviction index).
## Family 3 — Auxiliary Ordering Structures (stack, heap)
*Structure property: you don't traverse them — you maintain them while traversing something else.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Stack** (5) | LIFO memory of "unresolved" items; monotonic stack = discard dominated candidates | Matching/nesting (parens) · "next greater element" · "previous smaller" · expression eval |
| **Heap** (5) | Partial order — cheap access to extremum without full sort | "Kth largest/smallest" · "top K" · merge K streams · running median (two heaps) |
**Systems anchor:** monotonic stack ≈ log compaction (drop entries superseded by newer state); heap ≈ priority scheduling / Dijkstra's frontier / timer wheels.
## Family 4 — Hierarchical (trees, tries)
*Structure property: recursive shape — every node roots a subtree. Solutions are recurrences.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **DFS on trees** (part of 13) | Post/pre/in-order recursion; answer composed from subtree answers | "Max depth / diameter / LCA / validate" · anything defined recursively |
| **BFS on trees** (part of 8) | Level-order via queue | "Level by level" · "right side view" · minimum depth |
| **Trie** (2) | Character-indexed tree; shared prefixes = shared paths | Prefix search · autocomplete · word dictionaries · many-string matching |
| **BST specifically** | Sorted array in tree form — in-order traversal IS sorted order | "Kth smallest in BST" · range queries · validate |
**Systems anchor:** trie ≈ radix routing table / IPLD path resolution; BST invariant ≈ index B-tree.
## Family 5 — Relational (graphs)
*Structure property: arbitrary edges; must track visited. Trees are just acyclic connected graphs — same traversals, plus bookkeeping.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **DFS on graphs** (13) | Exhaustive reachability; recursion + visited set | Islands/regions/flood fill · connectivity · cycle detection (directed: 3-color) |
| **BFS on graphs** (8) | Frontier expansion → **shortest path in unweighted graphs, always** | "Minimum steps/moves" · multi-source spread (rotting oranges) · word ladder |
| **Graphs** (6): Topological sort | DFS post-order reversed / Kahn's in-degree queue over a DAG | Dependencies · prerequisites · build order · "valid ordering exists?" |
| **Graphs** (6): Union-Find | Incremental connectivity without traversal | Dynamic "same component?" queries · redundant edge · counting components |
**Systems anchor:** topo sort = dependency resolution (your Turborepo build graph); union-find = partition detection; BFS = gossip propagation. A matrix with neighbor-moves is ALWAYS this family, not Family 1.
## Family 6 — Decision-Space (implicit graphs you build while exploring)
*Structure property: nodes are STATES, not data. The structure doesn't exist until you walk it.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Backtracking** (6) | DFS over the state tree with undo; exhaustive enumeration | "All subsets/permutations/combinations" · constraint satisfaction · "generate all valid X" |
| **Dynamic Programming** (10) | Backtracking + memoization — overlapping subproblems collapse the exponential tree | "Count ways" · "min/max cost to reach" · choices with shared substructure · optimal substructure |
| **Greedy** (5) | DP where the local optimum provably suffices — no memo needed | Sort-then-commit works · exchange argument holds · intervals scheduling · jump game |
**Systems anchor:** DP memo = idempotency cache over a deterministic state machine; backtracking = saga with compensating undo; greedy = eventually-consistent local decisions that provably converge.
---
## The Recognition Decision Tree (run this in the first 2 minutes — rubric axis #1)
1. **Contiguous array/string, no neighbor semantics?** → Family 1. Sorted or monotonic answer space → Binary Search. Pair/window constraint → Two/Sliding. Range sums → Prefix.
2. **Nodes with next-pointers?** → Family 2. Reach for fast/slow or dummy-head before anything clever.
3. **Need "next greater," nesting, or top-K while scanning?** → Family 3 auxiliary structure on top of whatever you're traversing.
4. **Recursive shape (tree/prefix data)?** → Family 4. Ask: does the answer compose from subtrees (DFS) or from levels (BFS)?
5. **Arbitrary connections, grids with movement, dependencies?** → Family 5. Unweighted shortest = BFS. Ordering over DAG = topo. Dynamic connectivity = union-find. Otherwise DFS.
6. **Enumerate or optimize over CHOICES?** → Family 6. All solutions → backtracking. Overlapping subproblems → DP. Provable local choice → greedy.
## The Escalation Lattice (when stuck, patterns upgrade along these edges)
- Two Pointers —*add state*→ Sliding Window —*add aggregation*→ Prefix Sum
- Brute-force scan —*monotonic predicate*→ Binary Search on answer
- Tree DFS —*add visited set*→ Graph DFS —*add undo*→ Backtracking —*add memo*→ DP —*add proof*→ Greedy
- Sort —*need only extremum*→ Heap —*need running extremes*→ Monotonic Stack
- BFS —*add weights*→ Dijkstra (= BFS with a heap: Families 3+5 composed)
Memorize the lattice, not 16 patterns. In the interview, naming the family out loud ("this is a state-space problem, so backtracking or DP depending on overlap") IS the recognition signal the rubric scores.
@@ -0,0 +1,10 @@
---
title: 'Binary Search'
description: 'Halving over any monotonic predicate, not just sorted arrays.'
sidebar:
order: 5
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,21 @@
---
title: 'Contiguous Linear'
description: 'O(1) index access, order is information.'
sidebar:
order: 1
label: Introduction
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
## Patterns
- [Two Pointers](/guides/coding/contiguous-linear/two-pointers) — Converging/parallel index walk that prunes the O(n^2) pair space using order.
- [Sliding Window](/guides/coding/contiguous-linear/sliding-window) — Two pointers plus incremental state between them.
- [Prefix Sum](/guides/coding/contiguous-linear/prefix-sum) — Precomputed cumulative state for O(1) range queries.
- [Binary Search](/guides/coding/contiguous-linear/binary-search) — Halving over any monotonic predicate, not just sorted arrays.
- [Matrices](/guides/coding/contiguous-linear/matrices) — 2D index arithmetic; often a graph in disguise.
**Systems anchor:** Prefix sum is a materialized view; sliding window is stream processing with an eviction policy.
@@ -0,0 +1,10 @@
---
title: 'Matrices'
description: '2D index arithmetic; often a graph in disguise.'
sidebar:
order: 6
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,5 @@
import { defineMeta } from "blume";
export default defineMeta({
order: 4,
});
@@ -0,0 +1,10 @@
---
title: 'Prefix Sum'
description: 'Precomputed cumulative state for O(1) range queries.'
sidebar:
order: 4
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Sliding Window'
description: 'Two pointers plus incremental state between them.'
sidebar:
order: 3
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Two Pointers'
description: 'Converging/parallel index walk that prunes the O(n^2) pair space using order.'
sidebar:
order: 2
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,17 @@
---
title: 'Nodal Linear'
description: 'O(1) splice, no random access. Everything is pointer surgery.'
sidebar:
order: 1
label: Introduction
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
## Patterns
- [Linked List](/guides/coding/nodal-linear/linked-list) — Fast/slow runners, reversal, and dummy-head splicing cover it all.
**Systems anchor:** LRU cache = hashmap + doubly-linked list, the one hybrid that appears constantly.
@@ -0,0 +1,10 @@
---
title: 'Linked List'
description: 'Fast/slow runners, reversal, and dummy-head splicing cover it all.'
sidebar:
order: 2
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,5 @@
import { defineMeta } from "blume";
export default defineMeta({
order: 5,
});
@@ -0,0 +1,10 @@
---
title: 'Heap'
description: 'Partial order: cheap access to the extremum without a full sort.'
sidebar:
order: 3
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,18 @@
---
title: 'Auxiliary Ordering Structures'
description: 'You do not traverse them; you maintain them while traversing something else.'
sidebar:
order: 1
label: Introduction
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
## Patterns
- [Stack](/guides/coding/auxiliary-ordering/stack) — LIFO memory of unresolved items; monotonic stack discards dominated candidates.
- [Heap](/guides/coding/auxiliary-ordering/heap) — Partial order: cheap access to the extremum without a full sort.
**Systems anchor:** Monotonic stack is log compaction; heap is priority scheduling, Dijkstra's frontier, timer wheels.
@@ -0,0 +1,5 @@
import { defineMeta } from "blume";
export default defineMeta({
order: 6,
});
@@ -0,0 +1,10 @@
---
title: 'Stack'
description: 'LIFO memory of unresolved items; monotonic stack discards dominated candidates.'
sidebar:
order: 2
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Binary Search Tree'
description: 'A sorted array in tree form: in-order traversal is sorted order.'
sidebar:
order: 5
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,20 @@
---
title: 'Hierarchical'
description: 'Recursive shape: every node roots a subtree. Solutions are recurrences.'
sidebar:
order: 1
label: Introduction
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
## Patterns
- [DFS on Trees](/guides/coding/hierarchical/tree-dfs) — Post/pre/in-order recursion; the answer composes from subtree answers.
- [BFS on Trees](/guides/coding/hierarchical/tree-bfs) — Level-order traversal via a queue.
- [Trie](/guides/coding/hierarchical/trie) — Character-indexed tree; shared prefixes are shared paths.
- [Binary Search Tree](/guides/coding/hierarchical/binary-search-tree) — A sorted array in tree form: in-order traversal is sorted order.
**Systems anchor:** Trie is a radix routing table / IPLD path resolution; the BST invariant is a B-tree index.
@@ -0,0 +1,5 @@
import { defineMeta } from "blume";
export default defineMeta({
order: 7,
});
@@ -0,0 +1,10 @@
---
title: 'BFS on Trees'
description: 'Level-order traversal via a queue.'
sidebar:
order: 3
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'DFS on Trees'
description: 'Post/pre/in-order recursion; the answer composes from subtree answers.'
sidebar:
order: 2
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Trie'
description: 'Character-indexed tree; shared prefixes are shared paths.'
sidebar:
order: 4
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'BFS on Graphs'
description: 'Frontier expansion: shortest path in unweighted graphs, always.'
sidebar:
order: 3
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'DFS on Graphs'
description: 'Exhaustive reachability: recursion plus a visited set.'
sidebar:
order: 2
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,20 @@
---
title: 'Relational'
description: 'Arbitrary edges; you must track visited. Trees are acyclic connected graphs with less bookkeeping.'
sidebar:
order: 1
label: Introduction
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
## Patterns
- [DFS on Graphs](/guides/coding/relational/graph-dfs) — Exhaustive reachability: recursion plus a visited set.
- [BFS on Graphs](/guides/coding/relational/graph-bfs) — Frontier expansion: shortest path in unweighted graphs, always.
- [Topological Sort](/guides/coding/relational/topological-sort) — Reversed DFS post-order, or Kahn's in-degree queue over a DAG.
- [Union-Find](/guides/coding/relational/union-find) — Incremental connectivity without traversal.
**Systems anchor:** Topological sort is dependency resolution; union-find is partition detection; BFS is gossip propagation.
@@ -0,0 +1,5 @@
import { defineMeta } from "blume";
export default defineMeta({
order: 8,
});
@@ -0,0 +1,10 @@
---
title: 'Topological Sort'
description: "Reversed DFS post-order, or Kahn's in-degree queue over a DAG."
sidebar:
order: 4
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Union-Find'
description: 'Incremental connectivity without traversal.'
sidebar:
order: 5
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Backtracking'
description: 'DFS over the state tree with undo; exhaustive enumeration.'
sidebar:
order: 2
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Dynamic Programming'
description: 'Backtracking plus memoization over overlapping subproblems.'
sidebar:
order: 3
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,10 @@
---
title: 'Greedy'
description: 'DP where the local optimum provably suffices, so no memo is needed.'
sidebar:
order: 4
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
@@ -0,0 +1,19 @@
---
title: 'Decision-Space'
description: 'Nodes are states, not data. The structure does not exist until you walk it.'
sidebar:
order: 1
label: Introduction
---
:::warning[Under construction]
This page is a scaffold. Notes, canonical problems, and template code are not written yet.
:::
## Patterns
- [Backtracking](/guides/coding/decision-space/backtracking) — DFS over the state tree with undo; exhaustive enumeration.
- [Dynamic Programming](/guides/coding/decision-space/dynamic-programming) — Backtracking plus memoization over overlapping subproblems.
- [Greedy](/guides/coding/decision-space/greedy) — DP where the local optimum provably suffices, so no memo is needed.
**Systems anchor:** DP memo is an idempotency cache; backtracking is a saga with compensating undo; greedy is local decisions that converge.
@@ -0,0 +1,5 @@
import { defineMeta } from "blume";
export default defineMeta({
order: 9,
});
@@ -0,0 +1,96 @@
---
title: 'Coding'
description: 'There are only 6 structural families. Every pattern is a traversal or maintenance strategy over one of them.'
sidebar:
label: Overview
order: 1
---
## Family 1 — Contiguous Linear (arrays, strings)
*Structure property: O(1) index access, order is information.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Two Pointers** (7) | Converging/parallel index walk that prunes the O(n²) pair space using order | Sorted input · pair/triplet with target · palindrome · in-place partition |
| **Sliding Window** (5) | Two pointers + incremental state between them (Two Pointers with a payload) | "Longest/shortest substring/subarray with property X" · contiguous constraint |
| **Prefix Sum** (2) | Precomputed cumulative state → O(1) range queries | "Sum of range" · "subarray sum equals K" · repeated interval aggregation |
| **Binary Search** (5) | Halving over ANY monotonic predicate — not just sorted arrays | Sorted/rotated input · "minimize the maximum" · answer space is monotonic (Koko) |
| **Matrices** (3) | 2D index arithmetic; often a graph in disguise | Grid traversal/rotation/spiral · if cells have neighbors → it's Family 5 |
**Systems anchor:** prefix sum is a materialized view; sliding window is stream processing with an eviction policy.
## Family 2 — Nodal Linear (linked lists)
*Structure property: O(1) splice, no random access. Everything is pointer surgery.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Linked List** (5) | Three moves cover it all: fast/slow runners, reversal, dummy-head splicing | Cycle detection · middle/Nth-from-end · reverse/reorder · merge |
**Systems anchor:** LRU Cache = hashmap + doubly-linked list — the one hybrid that appears constantly (it's a cache eviction index).
## Family 3 — Auxiliary Ordering Structures (stack, heap)
*Structure property: you don't traverse them — you maintain them while traversing something else.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Stack** (5) | LIFO memory of "unresolved" items; monotonic stack = discard dominated candidates | Matching/nesting (parens) · "next greater element" · "previous smaller" · expression eval |
| **Heap** (5) | Partial order — cheap access to extremum without full sort | "Kth largest/smallest" · "top K" · merge K streams · running median (two heaps) |
**Systems anchor:** monotonic stack ≈ log compaction (drop entries superseded by newer state); heap ≈ priority scheduling / Dijkstra's frontier / timer wheels.
## Family 4 — Hierarchical (trees, tries)
*Structure property: recursive shape — every node roots a subtree. Solutions are recurrences.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **DFS on trees** (part of 13) | Post/pre/in-order recursion; answer composed from subtree answers | "Max depth / diameter / LCA / validate" · anything defined recursively |
| **BFS on trees** (part of 8) | Level-order via queue | "Level by level" · "right side view" · minimum depth |
| **Trie** (2) | Character-indexed tree; shared prefixes = shared paths | Prefix search · autocomplete · word dictionaries · many-string matching |
| **BST specifically** | Sorted array in tree form — in-order traversal IS sorted order | "Kth smallest in BST" · range queries · validate |
**Systems anchor:** trie ≈ radix routing table / IPLD path resolution; BST invariant ≈ index B-tree.
## Family 5 — Relational (graphs)
*Structure property: arbitrary edges; must track visited. Trees are just acyclic connected graphs — same traversals, plus bookkeeping.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **DFS on graphs** (13) | Exhaustive reachability; recursion + visited set | Islands/regions/flood fill · connectivity · cycle detection (directed: 3-color) |
| **BFS on graphs** (8) | Frontier expansion → **shortest path in unweighted graphs, always** | "Minimum steps/moves" · multi-source spread (rotting oranges) · word ladder |
| **Graphs** (6): Topological sort | DFS post-order reversed / Kahn's in-degree queue over a DAG | Dependencies · prerequisites · build order · "valid ordering exists?" |
| **Graphs** (6): Union-Find | Incremental connectivity without traversal | Dynamic "same component?" queries · redundant edge · counting components |
**Systems anchor:** topo sort = dependency resolution (your Turborepo build graph); union-find = partition detection; BFS = gossip propagation. A matrix with neighbor-moves is ALWAYS this family, not Family 1.
## Family 6 — Decision-Space (implicit graphs you build while exploring)
*Structure property: nodes are STATES, not data. The structure doesn't exist until you walk it.*
| Pattern | What it really is | Recognition triggers |
|---|---|---|
| **Backtracking** (6) | DFS over the state tree with undo; exhaustive enumeration | "All subsets/permutations/combinations" · constraint satisfaction · "generate all valid X" |
| **Dynamic Programming** (10) | Backtracking + memoization — overlapping subproblems collapse the exponential tree | "Count ways" · "min/max cost to reach" · choices with shared substructure · optimal substructure |
| **Greedy** (5) | DP where the local optimum provably suffices — no memo needed | Sort-then-commit works · exchange argument holds · intervals scheduling · jump game |
**Systems anchor:** DP memo = idempotency cache over a deterministic state machine; backtracking = saga with compensating undo; greedy = eventually-consistent local decisions that provably converge.
---
## The Recognition Decision Tree (run this in the first 2 minutes — rubric axis #1)
1. **Contiguous array/string, no neighbor semantics?** → Family 1. Sorted or monotonic answer space → Binary Search. Pair/window constraint → Two/Sliding. Range sums → Prefix.
2. **Nodes with next-pointers?** → Family 2. Reach for fast/slow or dummy-head before anything clever.
3. **Need "next greater," nesting, or top-K while scanning?** → Family 3 auxiliary structure on top of whatever you're traversing.
4. **Recursive shape (tree/prefix data)?** → Family 4. Ask: does the answer compose from subtrees (DFS) or from levels (BFS)?
5. **Arbitrary connections, grids with movement, dependencies?** → Family 5. Unweighted shortest = BFS. Ordering over DAG = topo. Dynamic connectivity = union-find. Otherwise DFS.
6. **Enumerate or optimize over CHOICES?** → Family 6. All solutions → backtracking. Overlapping subproblems → DP. Provable local choice → greedy.
## The Escalation Lattice (when stuck, patterns upgrade along these edges)
- Two Pointers —*add state*→ Sliding Window —*add aggregation*→ Prefix Sum
- Brute-force scan —*monotonic predicate*→ Binary Search on answer
- Tree DFS —*add visited set*→ Graph DFS —*add undo*→ Backtracking —*add memo*→ DP —*add proof*→ Greedy
- Sort —*need only extremum*→ Heap —*need running extremes*→ Monotonic Stack
- BFS —*add weights*→ Dijkstra (= BFS with a heap: Families 3+5 composed)
Memorize the lattice, not 16 patterns. In the interview, naming the family out loud ("this is a state-space problem, so backtracking or DP depending on overlap") IS the recognition signal the rubric scores.
+9
View File
@@ -0,0 +1,9 @@
import { defineMeta } from "blume";
export default defineMeta({
title: "Coding",
order: 1,
collapsed: true,
icon: "code-xml",
display: "page",
});