[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AK7WE8MT223V5VQPDZV0DF":3,"skill-same:01M7AK7WE8MT223V5VQPDZV0DF":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M7AK7WE8MT223V5VQPDZV0DF","algo-core-algorithms",null,"Use when implementing or choosing a core algorithm: sorting as libraries actually implement it (introsort, Timsort, pdqsort, radix) and how to choose, searching and indexing, graph algorithms (traversal, shortest paths, topological sort, flow, union-find), string and text algorithms (substring search, edit distance, suffix structures), and dynamic programming, greedy, divide and conquer, and amortized analysis.","the-vibey-project\u002Fvibey","the-vibey-project","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F329298758?v=4","01M7AJHGZ9722CTJ4JNQZVRH0Q","the vibey project","01M7AJHGZVMG2K7TGXQ6XFHVG3",5,"MIT","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Falgorithms-deep-dive\u002Fskills\u002Falgo-core-algorithms\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: algo-core-algorithms\ndescription: \"Use when implementing or choosing a core algorithm: sorting as libraries actually implement it (introsort, Timsort, pdqsort, radix) and how to choose, searching and indexing, graph algorithms (traversal, shortest paths, topological sort, flow, union-find), string and text algorithms (substring search, edit distance, suffix structures), and dynamic programming, greedy, divide and conquer, and amortized analysis.\"\n---\n\n# Algorithms Deep Dive: Sorting, Searching, Graphs, Strings, and Dynamic Programming\n\n> **Part 3 of 5** of the *Algorithms Deep Dive* reference (plugin `algorithms-deep-dive`), covering §7–§11. Sibling skills: `algo-foundations-and-machine-model` (§0–§2), `algo-data-structures` (§3–§6), `algo-probabilistic-concurrency-and-measurement` (§12–§14), `algo-reference` (§15–§20). Section numbers are shared across the set; a reference written as §N → `skill` points into that sibling skill.\n>\n> **Currency:** Verified August 2026. See §17 → `algo-reference` for the currency snapshot and what goes stale first.\n\n> **How to read this.** Reference, not a course, and deliberately complementary to a\n> theory-of-computation reference: **that** answers \"is this solvable and how hard is it\";\n> **this** answers \"which structure, which algorithm, and why is it slower than the\n> analysis said.\"\n>\n> Three markers:\n> - **[DURABLE]** — established algorithms, structures, and engineering practice. Most of\n>   this document.\n> - **[VERSIONED]** — library implementations, hardware behaviour, recent results.\n> - **[CONTESTED]** — genuine disagreement.\n>\n> **⚠️ GOTCHA** boxes mark the places where the textbook answer and the production answer\n> diverge.\n>\n> **The three framings that organize everything below:**\n> 1. **Data structure choice is algorithm choice.** Most \"algorithm problems\" in real\n>    systems are solved by picking the right structure and letting the algorithm fall out.\n>    **If your algorithm is complicated, your data layout is probably wrong** (§3–§7 → `algo-data-structures`).\n> 2. **Asymptotic analysis models the wrong machine.** It assumes uniform-cost memory\n>    access, which stopped being true in the 1990s. **A cache miss is ~100× an arithmetic\n>    op, and a branch mispredict ~15–20 cycles** — so an O(n) scan over an array routinely\n>    beats an O(log n) walk over a pointer structure (§2 → `algo-foundations-and-machine-model`). Asymptotics tell you how\n>    something scales; they do not tell you which is faster at your n.\n> 3. **You will almost never write these.** You will *choose* them. The valuable skill is\n>    knowing what your standard library actually does, what its failure modes are, and\n>    when its default is wrong for your data — not reimplementing quicksort (§13 → `algo-probabilistic-concurrency-and-measurement`).\n\n---\n\n## §7. Sorting\n\n### 7.1 What your library actually does\n\n**[DURABLE] Nobody ships a textbook sort.** Every serious standard library uses a hybrid,\nand knowing which one tells you its behaviour.\n\n| Family | Where |\n|---|---|\n| **Introsort** — quicksort + heapsort fallback + insertion sort for small runs | C++ `std::sort`, historically |\n| **pdqsort** (pattern-defeating quicksort) | Adds **branchless partitioning**, pattern detection, and adversarial-input handling. Widely adopted |\n| **Timsort** — adaptive natural mergesort | Python `sorted`, Java objects, **stable**, exploits existing runs |\n| **Powersort** — Timsort with provably near-optimal merge policy | Adopted in CPython |\n| **Radix \u002F counting sort** — non-comparison, O(n·k) | Fixed-width keys; ⚠️ genuinely faster when applicable |\n\n**[VERSIONED] The current state of the art is worth knowing as a concrete example of §2 → `algo-foundations-and-machine-model` in\naction.** Rust's standard library replaced its sorts in 2024 with **driftsort** (stable,\nderived from glidesort) and **ipnsort** (unstable). Reported gains: **ipnsort up to ~2.4×\nfaster on random inputs**; **driftsort up to ~17× faster on low-cardinality patterns**.\n\n**⚠️ The design choices are the instructive part**: both **prefer instruction-level\nparallelism over SIMD** — because ILP generalizes across architectures and data types while\nSIMD depends on specific vector instruction sets — and both are **optimized to minimize\ni-cache misses**, a factor automated instruction-count analysis doesn't capture. Rust's\n`sort_unstable` documents that ipnsort **achieves linear time on fully sorted and reversed\ninputs**, and **O(n log k) on inputs with k distinct elements**.\n\n### 7.2 Choosing\n\n```\nNeed stability?          → stable sort (Timsort\u002Fdriftsort\u002Fstd::stable_sort)\nFixed-width integer keys → radix sort can beat comparison sorting outright\nNearly sorted data       → adaptive sorts (Timsort family) approach O(n)\nSmall n (\u003C ~20)          → insertion sort. This is what hybrids do internally\nTop-k only               → heap, O(n log k). Don't sort (§6)\nk-th element only        → quickselect, O(n) average (introselect for worst case)\nLarger than memory       → external merge sort\nSort key expensive       → decorate-sort-undecorate (Schwartzian transform)\n```\n\n**[DURABLE] The comparison lower bound is Ω(n log n)** — and **radix sort doesn't violate\nit**, because it isn't comparison-based. That distinction is worth being precise about.\n\n**⚠️ Comparator correctness is a real production bug source.** Your comparator must define\na **strict weak ordering** — irreflexive, antisymmetric, transitive, with transitive\nincomparability. Violating it is undefined behaviour and **can crash or corrupt memory in\nC++**; Rust's `sort_unstable` documents that it \"may panic if `Ord` does not implement a\ntotal order.\" **NaN in a float comparator is the classic trigger.**\n\n---\n\n## §8. Searching and Indexing\n\n**Binary search** — O(log n), and **⚠️ notoriously easy to get wrong** (the overflow in\n`(lo+hi)\u002F2` shipped in the JDK for years). **Use the library.** The variants that matter\nare `lower_bound`\u002F`upper_bound` — \"first element ≥ x\" is more often what you want than\n\"is x present.\"\n\n**⚠️ Interpolation search** is O(log log n) on uniform data and O(n) on skewed data.\n**Branchless \u002F Eytzinger-layout binary search** rearranges the array in BFS order for\nbetter cache behaviour — a real win for repeated searches on a static array.\n\n**Inverted indexes** — the core of full-text search: term → posting list, with\nskip pointers, compression (delta + varint\u002FPFOR), and scoring (BM25). **If you're building\nsearch, you're building this or using Lucene.**\n\n**Bitmap indexes** — **Roaring bitmaps** are the practical standard: hybrid\narray\u002Fbitmap\u002Frun containers, and **the right answer for large set intersection**,\nwhich is what filtered search reduces to.\n\n**Spatial indexes** — R-trees (rectangles, the standard in spatial DBs), k-d trees\n(⚠️ **degrade badly above ~20 dimensions** — the curse of dimensionality), quadtrees \u002F\noctrees, **geohash and S2\u002FH3** for lat-long. Which is why high-dimensional similarity\nneeds an entirely different approach (§13.4 → `algo-probabilistic-concurrency-and-measurement`).\n\n---\n\n## §9. Graphs\n\n**[DURABLE] Representation is the first decision and it's usually adjacency lists** —\nadjacency matrices cost O(V²) space and only win for genuinely dense graphs or when you\nneed O(1) edge existence checks. **CSR (compressed sparse row)** is the cache-friendly\nstatic form and is what serious graph processing uses.\n\n**The traversals**: **BFS** (shortest path in *unweighted* graphs, level order),\n**DFS** (cycle detection, topological sort, SCC, backtracking — ⚠️ **use an explicit stack\nin production**; recursion depth on a large graph is a stack overflow).\n\n**Shortest paths, and picking the right one:**\n\n| Algorithm | Use | Complexity |\n|---|---|---|\n| **BFS** | Unweighted | O(V+E) |\n| **Dijkstra** | Non-negative weights | O((V+E) log V) with a heap |\n| **A\\*** | Single target with a good heuristic | Dijkstra + admissible heuristic |\n| **Bellman-Ford** | ⚠️ **Negative weights**; detects negative cycles | O(VE) |\n| **Floyd-Warshall** | All pairs, small dense graphs | O(V³) |\n| **Bidirectional search** | Point-to-point on large graphs | Often dramatically better |\n\n**⚠️ Dijkstra silently gives wrong answers with negative edges.** It doesn't error; it\nreturns a plausible wrong path. Know which one you need.\n\n**Also**: **topological sort** (build systems, task scheduling, dependency resolution —\nand cycle detection is the same algorithm), **union-find** for connectivity and Kruskal's,\n**Prim's** for MST, **max-flow\u002Fmin-cut** (Dinic's in practice; the reduction target for a\nsurprising number of assignment and matching problems), **bipartite matching**,\n**PageRank** and centrality, and **community detection**.\n\n**[DURABLE] Recognizing that your problem is a graph problem is most of the work.**\nDependency resolution, permissions inheritance, routing, scheduling, deduplication,\nrecommendation, and data lineage are all graph problems wearing business costumes.\n\n---\n\n## §10. Strings and Text\n\n**Exact search**: **Boyer-Moore** and variants skip ahead and are sublinear in practice;\n**KMP** is linear with no worst case; **Rabin-Karp** uses rolling hashes and generalizes\nto multiple patterns; **Aho-Corasick** matches many patterns in one pass and is **the right\nanswer for keyword\u002Fblocklist scanning**. **⚠️ In practice, `memmem`\u002F`std::string::find`\nwith SIMD beats naive implementations of all of these** — measure before implementing.\n\n**Structures**: **suffix arrays** (+ LCP) — practical, compact, and the usual choice over\n**suffix trees** (asymptotically nice, memory-hungry). **FM-index \u002F BWT** for compressed\nfull-text search (the basis of genomic aligners). **Tries and ARTs** (§5.3 → `algo-data-structures`).\n\n**Edit distance and similarity**: Levenshtein is O(mn) DP — **and §9 of a\ntheory-of-computation reference explains why that's conditionally optimal under SETH, so\ndon't try to beat it asymptotically**. Practical answers: bound the edit distance\n(banded DP), use **Myers' bit-parallel algorithm**, or switch measures — **SimHash\u002FMinHash\nfor near-duplicate detection at scale**, n-gram similarity, or trigram indexes.\n\n**⚠️ Unicode will hurt you.** Normalization forms (NFC\u002FNFD\u002FNFKC\u002FNFKD), grapheme clusters vs.\ncode points vs. bytes, case folding that isn't symmetric, collation that's\nlocale-dependent. **\"Reverse a string\" and \"uppercase a string\" are not simple operations**\nand treating them as such is a recurring source of bugs in international products.\n\n---\n\n## §11. Dynamic Programming, Greedy, and Amortization\n\n### 11.1 Dynamic programming\n\n**[DURABLE] The recognition test: optimal substructure plus overlapping subproblems.**\nIf a problem's optimal solution is built from optimal solutions to subproblems, and those\nsubproblems repeat, it's DP.\n\n**Top-down (memoization)** is easier to write and follows the recursion naturally;\n**bottom-up (tabulation)** avoids recursion overhead and enables **space optimization** —\n**⚠️ most DP tables only need the last row or two, turning O(n·m) space into O(m)**, which\nis frequently the difference between fitting in cache and not.\n\n**The classic patterns worth recognizing**: knapsack, LCS\u002Fedit distance, longest increasing\nsubsequence (**⚠️ the O(n log n) patience-sorting version, not the O(n²) one**), matrix\nchain, interval scheduling, coin change, and DP over subsets\u002Fbitmasks (2ⁿ·n — fine for\nn ≤ 20).\n\n### 11.2 Greedy\n\nWorks when the **greedy choice property** holds — a locally optimal choice is globally\nsafe. **⚠️ Greedy is right far less often than it looks right, and the failure is silent:**\nyou get a plausible suboptimal answer, not an error. **Either prove the exchange argument\nor test against brute force on small inputs.**\n\n### 11.3 Divide and conquer\nMergesort, quicksort, FFT, Karatsuba, Strassen, closest pair. **The Master Theorem** gives\nthe complexity for the standard recurrence shapes.\n\n### 11.4 Amortized analysis\n\n**[DURABLE] Amortized O(1) means \"cheap on average across a sequence,\" not \"cheap every\ntime.\"** Dynamic array growth, hash table resize, union-find with path compression, and\nsplay trees are all amortized.\n\n**⚠️ This is a latency-tail issue, and it's the most under-appreciated point here.**\nAmortized-cheap structures have **occasional expensive operations**, and if you have a p99\nlatency budget, that occasional O(n) resize is exactly what shows up there. **For strict\nlatency bounds, prefer structures with good worst-case behaviour, or pre-size to avoid the\nresize entirely.**\n","# Algorithms Deep Dive: Sorting, Searching, Graphs, Strings, and Dynamic Programming\n\n> **Part 3 of 5** of the *Algorithms Deep Dive* reference (plugin `algorithms-deep-dive`), covering §7–§11. Sibling skills: `algo-foundations-and-machine-model` (§0–§2), `algo-data-structures` (§3–§6), `algo-probabilistic-concurrency-and-measurement` (§12–§14), `algo-reference` (§15–§20). Section numbers are shared across the set; a reference written as §N → `skill` points into that sibling skill.\n>\n> **Currency:** Verified August 2026. See §17 → `algo-reference` for the currency snapshot and what goes stale first.\n\n> **How to read this.** Reference, not a course, and deliberately complementary to a\n> theory-of-computation reference: **that** answers \"is this solvable and how hard is it\";\n> **this** answers \"which structure, which algorithm, and why is it slower than the\n> analysis said.\"\n>\n> Three markers:\n> - **[DURABLE]** — established algorithms, structures, and engineering practice. Most of\n>   this document.\n> - **[VERSIONED]** — library implementations, hardware behaviour, recent results.\n> - **[CONTESTED]** — genuine disagreement.\n>\n> **⚠️ GOTCHA** boxes mark the places where the textbook answer and the production answer\n> diverge.\n>\n> **The three framings that organize everything below:**\n> 1. **Data structure choice is algorithm choice.** Most \"algorithm problems\" in real\n>    systems are solved by picking the right structure and letting the algorithm fall out.\n>    **If your algorithm is complicated, your data layout is probably wrong** (§3–§7 → `algo-data-structures`).\n> 2. **Asymptotic analysis models the wrong machine.** It assumes uniform-cost memory\n>    access, which stopped being true in the 1990s. **A cache miss is ~100× an arithmetic\n>    op, and a branch mispredict ~15–20 cycles** — so an O(n) scan over an array routinely\n>    beats an O(log n) walk over a pointer structure (§2 → `algo-foundations-and-machine-model`). Asymptotics tell you how\n>    something scales; they do not tell you which is faster at your n.\n> 3. **You will almost never write these.** You will *choose* them. The valuable skill is\n>    knowing what your standard library actually does, what its failure modes are, and\n>    when its default is wrong for your data — not reimplementing quicksort (§13 → `algo-probabilistic-concurrency-and-measurement`).\n\n---\n\n## §7. Sorting\n\n### 7.1 What your library actually does\n\n**[DURABLE] Nobody ships a textbook sort.** Every serious standard library uses a hybrid,\nand knowing which one tells you its behaviour.\n\n| Family | Where |\n|---|---|\n| **Introsort** — quicksort + heapsort fallback + insertion sort for small runs | C++ `std::sort`, historically |\n| **pdqsort** (pattern-defeating quicksort) | Adds **branchless partitioning**, pattern detection, and adversarial-input handling. Widely adopted |\n| **Timsort** — adaptive natural mergesort | Python `sorted`, Java objects, **stable**, exploits existing runs |\n| **Powersort** — Timsort with provably near-optimal merge policy | Adopted in CPython |\n| **Radix \u002F counting sort** — non-comparison, O(n·k) | Fixed-width keys; ⚠️ genuinely faster when applicable |\n\n**[VERSIONED] The current state of the art is worth knowing as a concrete example of §2 → `algo-foundations-and-machine-model` in\naction.** Rust's standard library replaced its sorts in 2024 with **driftsort** (stable,\nderived from glidesort) and **ipnsort** (unstable). Reported gains: **ipnsort up to ~2.4×\nfaster on random inputs**; **driftsort up to ~17× faster on low-cardinality patterns**.\n\n**⚠️ The design choices are the instructive part**: both **prefer instruction-level\nparallelism over SIMD** — because ILP generalizes across architectures and data types while\nSIMD depends on specific vector instruction sets — and both are **optimized to minimize\ni-cache misses**, a factor automated instruction-count analysis doesn't capture. Rust's\n`sort_unstable` documents that ipnsort **achieves linear time on fully sorted and reversed\ninputs**, and **O(n log k) on inputs with k distinct elements**.\n\n### 7.2 Choosing\n\n```\nNeed stability?          → stable sort (Timsort\u002Fdriftsort\u002Fstd::stable_sort)\nFixed-width integer keys → radix sort can beat comparison sorting outright\nNearly sorted data       → adaptive sorts (Timsort family) approach O(n)\nSmall n (\u003C ~20)          → insertion sort. This is what hybrids do internally\nTop-k only               → heap, O(n log k). Don't sort (§6)\nk-th element only        → quickselect, O(n) average (introselect for worst case)\nLarger than memory       → external merge sort\nSort key expensive       → decorate-sort-undecorate (Schwartzian transform)\n```\n\n**[DURABLE] The comparison lower bound is Ω(n log n)** — and **radix sort doesn't violate\nit**, because it isn't comparison-based. That distinction is worth being precise about.\n\n**⚠️ Comparator correctness is a real production bug source.** Your comparator must define\na **strict weak ordering** — irreflexive, antisymmetric, transitive, with transitive\nincomparability. Violating it is undefined behaviour and **can crash or corrupt memory in\nC++**; Rust's `sort_unstable` documents that it \"may panic if `Ord` does not implement a\ntotal order.\" **NaN in a float comparator is the classic trigger.**\n\n---\n\n## §8. Searching and Indexing\n\n**Binary search** — O(log n), and **⚠️ notoriously easy to get wrong** (the overflow in\n`(lo+hi)\u002F2` shipped in the JDK for years). **Use the library.** The variants that matter\nare `lower_bound`\u002F`upper_bound` — \"first element ≥ x\" is more often what you want than\n\"is x present.\"\n\n**⚠️ Interpolation search** is O(log log n) on uniform data and O(n) on skewed data.\n**Branchless \u002F Eytzinger-layout binary search** rearranges the array in BFS order for\nbetter cache behaviour — a real win for repeated searches on a static array.\n\n**Inverted indexes** — the core of full-text search: term → posting list, with\nskip pointers, compression (delta + varint\u002FPFOR), and scoring (BM25). **If you're building\nsearch, you're building this or using Lucene.**\n\n**Bitmap indexes** — **Roaring bitmaps** are the practical standard: hybrid\narray\u002Fbitmap\u002Frun containers, and **the right answer for large set intersection**,\nwhich is what filtered search reduces to.\n\n**Spatial indexes** — R-trees (rectangles, the standard in spatial DBs), k-d trees\n(⚠️ **degrade badly above ~20 dimensions** — the curse of dimensionality), quadtrees \u002F\noctrees, **geohash and S2\u002FH3** for lat-long. Which is why high-dimensional similarity\nneeds an entirely different approach (§13.4 → `algo-probabilistic-concurrency-and-measurement`).\n\n---\n\n## §9. Graphs\n\n**[DURABLE] Representation is the first decision and it's usually adjacency lists** —\nadjacency matrices cost O(V²) space and only win for genuinely dense graphs or when you\nneed O(1) edge existence checks. **CSR (compressed sparse row)** is the cache-friendly\nstatic form and is what serious graph processing uses.\n\n**The traversals**: **BFS** (shortest path in *unweighted* graphs, level order),\n**DFS** (cycle detection, topological sort, SCC, backtracking — ⚠️ **use an explicit stack\nin production**; recursion depth on a large graph is a stack overflow).\n\n**Shortest paths, and picking the right one:**\n\n| Algorithm | Use | Complexity |\n|---|---|---|\n| **BFS** | Unweighted | O(V+E) |\n| **Dijkstra** | Non-negative weights | O((V+E) log V) with a heap |\n| **A\\*** | Single target with a good heuristic | Dijkstra + admissible heuristic |\n| **Bellman-Ford** | ⚠️ **Negative weights**; detects negative cycles | O(VE) |\n| **Floyd-Warshall** | All pairs, small dense graphs | O(V³) |\n| **Bidirectional search** | Point-to-point on large graphs | Often dramatically better |\n\n**⚠️ Dijkstra silently gives wrong answers with negative edges.** It doesn't error; it\nreturns a plausible wrong path. Know which one you need.\n\n**Also**: **topological sort** (build systems, task scheduling, dependency resolution —\nand cycle detection is the same algorithm), **union-find** for connectivity and Kruskal's,\n**Prim's** for MST, **max-flow\u002Fmin-cut** (Dinic's in practice; the reduction target for a\nsurprising number of assignment and matching problems), **bipartite matching**,\n**PageRank** and centrality, and **community detection**.\n\n**[DURABLE] Recognizing that your problem is a graph problem is most of the work.**\nDependency resolution, permissions inheritance, routing, scheduling, deduplication,\nrecommendation, and data lineage are all graph problems wearing business costumes.\n\n---\n\n## §10. Strings and Text\n\n**Exact search**: **Boyer-Moore** and variants skip ahead and are sublinear in practice;\n**KMP** is linear with no worst case; **Rabin-Karp** uses rolling hashes and generalizes\nto multiple patterns; **Aho-Corasick** matches many patterns in one pass and is **the right\nanswer for keyword\u002Fblocklist scanning**. **⚠️ In practice, `memmem`\u002F`std::string::find`\nwith SIMD beats naive implementations of all of these** — measure before implementing.\n\n**Structures**: **suffix arrays** (+ LCP) — practical, compact, and the usual choice over\n**suffix trees** (asymptotically nice, memory-hungry). **FM-index \u002F BWT** for compressed\nfull-text search (the basis of genomic aligners). **Tries and ARTs** (§5.3 → `algo-data-structures`).\n\n**Edit distance and similarity**: Levenshtein is O(mn) DP — **and §9 of a\ntheory-of-computation reference explains why that's conditionally optimal under SETH, so\ndon't try to beat it asymptotically**. Practical answers: bound the edit distance\n(banded DP), use **Myers' bit-parallel algorithm**, or switch measures — **SimHash\u002FMinHash\nfor near-duplicate detection at scale**, n-gram similarity, or trigram indexes.\n\n**⚠️ Unicode will hurt you.** Normalization forms (NFC\u002FNFD\u002FNFKC\u002FNFKD), grapheme clusters vs.\ncode points vs. bytes, case folding that isn't symmetric, collation that's\nlocale-dependent. **\"Reverse a string\" and \"uppercase a string\" are not simple operations**\nand treating them as such is a recurring source of bugs in international products.\n\n---\n\n## §11. Dynamic Programming, Greedy, and Amortization\n\n### 11.1 Dynamic programming\n\n**[DURABLE] The recognition test: optimal substructure plus overlapping subproblems.**\nIf a problem's optimal solution is built from optimal solutions to subproblems, and those\nsubproblems repeat, it's DP.\n\n**Top-down (memoization)** is easier to write and follows the recursion naturally;\n**bottom-up (tabulation)** avoids recursion overhead and enables **space optimization** —\n**⚠️ most DP tables only need the last row or two, turning O(n·m) space into O(m)**, which\nis frequently the difference between fitting in cache and not.\n\n**The classic patterns worth recognizing**: knapsack, LCS\u002Fedit distance, longest increasing\nsubsequence (**⚠️ the O(n log n) patience-sorting version, not the O(n²) one**), matrix\nchain, interval scheduling, coin change, and DP over subsets\u002Fbitmasks (2ⁿ·n — fine for\nn ≤ 20).\n\n### 11.2 Greedy\n\nWorks when the **greedy choice property** holds — a locally optimal choice is globally\nsafe. **⚠️ Greedy is right far less often than it looks right, and the failure is silent:**\nyou get a plausible suboptimal answer, not an error. **Either prove the exchange argument\nor test against brute force on small inputs.**\n\n### 11.3 Divide and conquer\nMergesort, quicksort, FFT, Karatsuba, Strassen, closest pair. **The Master Theorem** gives\nthe complexity for the standard recurrence shapes.\n\n### 11.4 Amortized analysis\n\n**[DURABLE] Amortized O(1) means \"cheap on average across a sequence,\" not \"cheap every\ntime.\"** Dynamic array growth, hash table resize, union-find with path compression, and\nsplay trees are all amortized.\n\n**⚠️ This is a latency-tail issue, and it's the most under-appreciated point here.**\nAmortized-cheap structures have **occasional expensive operations**, and if you have a p99\nlatency budget, that occasional O(n) resize is exactly what shows up there. **For strict\nlatency bounds, prefer structures with good worst-case behaviour, or pre-size to avoid the\nresize entirely.**\n",{"name":5,"description":7},"develop","ae32736a1aabddabca5d2c96d665aa0ebc7d8700","src\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Falgorithms-deep-dive\u002Fskills\u002Falgo-core-algorithms",3,"https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey","https:\u002F\u002Fthe-vibey-project.github.io\u002Fvibey\u002F","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project","https:\u002F\u002Fvibewithadam.matthewsteinberger.com","freedom for software engineers","2026-11-15 05:47:42",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add the-vibey-project\u002Fvibey --skill algo-core-algorithms",{"tool":40,"command":41},"bunx","bunx skills add the-vibey-project\u002Fvibey --skill algo-core-algorithms",{"tool":43,"command":44},"pnpm","pnpm dlx skills add the-vibey-project\u002Fvibey --skill algo-core-algorithms","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Falgorithms-deep-dive\u002Fskills\u002Falgo-core-algorithms\u002FSKILL.md",true,[],[49,56,63,70,77,84],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":19},"01M7AT1FQJAE1FQYAMDTF490Y4","white-paper-writing","Use when writing white papers, technical reports, policy documents, thought leadership pieces, or any long-form authoritative document. Triggers on requests to write, structure, outline, or review white papers, technical reports, position papers, policy briefs, or evidence-driven arguments. Also use for B2B content marketing strategy, technical documentation requiring authority, academic-style reports, or any document that must educate while persuading. Use when someone asks \"how should I structure this\" for a long-form document.","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Fwriting-craft\u002Fskills\u002Fwhite-paper-writing\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M7AT16BJRJJKK2MASXRZS76G","prose-technical-mechanics","Use when editing or writing prose at a technical\u002Fmechanical level: choosing between Anglo-Saxon and Latinate diction, placing information in topic vs stress positions, writing periodic vs cumulative sentences, handling sentence rhythm, punctuation as logic, transitions, paragraph structure, or phonesthetics. Use when someone wants to understand WHY prose works or doesn't, not just surface-level style advice. Triggers on word choice, sentence structure, emphasis, rhythm, diction, or any deep writing mechanics question.","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Fwriting-craft\u002Fskills\u002Fprose-technical-mechanics\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M7AT0W9HT0ZZ9Y287NW99MR3","prose-mechanics","Use when writing, editing, or analyzing prose style; when trying to avoid generic AI-sounding writing; when applying specific prose styles such as journalistic, academic, narrative, KJV biblical, Hemingway plain, Latinate\u002FJamesian, Orwellian, Augustan, Victorian, Early Modern (Bacon, Browne, Milton), or free indirect discourse; or when coaching someone on writing voice and mechanics. Triggers on any request to improve, analyze, or write in a specific prose style, to fix \"AI-sounding\" writing, to make prose more vivid or concrete, to vary sentence rhythm, or to understand how a particular writer achieves their effects.","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Fwriting-craft\u002Fskills\u002Fprose-mechanics\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M7AT0KR635JX66X2X6F3E2CP","narrative-structure","Use when structuring stories, pitches, presentations, white papers, or any persuasive narrative; analyzing the hero's journey in fiction or non-fiction; applying StoryBrand for business communication; designing narrative arcs for thought leadership; or understanding Vogler, Snyder, Propp, or Campbell frameworks. Triggers on any narrative structure, storytelling, pitch structure, StoryBrand, hero's journey, three-act structure, Freytag, Save the Cat, narrative arc, or \"how should I structure this story\u002Fpitch\u002Fpresentation\" request.","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Fwriting-craft\u002Fskills\u002Fnarrative-structure\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M7AT0AKGW09NKKZDYBT8VRDE","legal-brief-writing","Use when writing legal briefs, motions, or any court filing; when analyzing judicial cognition and persuasion; when applying elite brief-writing techniques from Roberts, Clement, Kagan, Garner; or when structuring legal arguments for maximum persuasion. Also use for autistic\u002Fneurodivergent advocates who need to understand how their natural communication style maps to elite legal advocacy. Triggers on any legal writing, brief drafting, motion preparation, or legal argument structuring request.","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Fwriting-craft\u002Fskills\u002Flegal-brief-writing\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M7AT00VWPS4Q8B5VEMXX9NQT","journal-publishability-criteria","Use whenever a research paper, article or preprint is being written, revised, reviewed or published, and specifically before every publication of docs\u002Fpaper.md. Covers what legitimate journals actually gate on, in order of gating — the editor's desk screen (scope, novelty, package problems), what reviewers judge (methodological soundness, claims the evidence can carry, statistical and qualitative reporting), EQUATOR reporting guidelines, the ICMJE authorship criteria, COPE's view of text recycling, the near-universal generative-AI policy (no AI author, disclosure, author responsibility), TOP 2025 transparency standards, how to verify a journal is legitimate, submitting without an institution, and a pre-submission checklist. Triggers on requests to evaluate, review, prepare or submit a paper, to judge publishability, to write a declarations or data-availability section, to disclose AI use, or to check a journal.","https:\u002F\u002Fgithub.com\u002Fthe-vibey-project\u002Fvibey\u002Fblob\u002Fdevelop\u002Fsrc\u002Fvibey_tools\u002Fskills\u002Fplugins\u002Fwriting-craft\u002Fskills\u002Fjournal-publishability-criteria\u002FSKILL.md",[],[]]