{
    "version": "https://jsonfeed.org/version/1",
    "title": "study · notes",
    "home_page_url": "https://notes.amittai.studio",
    "feed_url": "https://notes.amittai.studio/feed/json",
    "description": "A reference for the ideas behind computer science.",
    "author": {
        "name": "Amittai Siavava",
        "url": "https://amittai.studio"
    },
    "items": [
        {
            "id": "https://notes.amittai.studio/algorithms/foundations/what-is-an-algorithm",
            "content_html": "An algorithm is a finite, mechanical recipe that transforms inputs into outputs. We pin down what counts as an algorithm, how we write one down, and the three things we always ask of it: is it correct, is it fast, and can we prove it.\n",
            "url": "https://notes.amittai.studio/algorithms/foundations/what-is-an-algorithm",
            "title": "What Is an Algorithm?",
            "date_modified": "2026-01-01T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/foundations/asymptotic-analysis",
            "content_html": "We measure an algorithm's running time as a function of its input size, then strip away machine-specific constants and lower-order terms to compare algorithms cleanly. This lesson defines the RAM model and the $O$, $\\Omega$, $\\Theta$, $o$, and $\\omega$ notations, and shows how to read the cost of loops off the page.\n",
            "url": "https://notes.amittai.studio/algorithms/foundations/asymptotic-analysis",
            "title": "Asymptotic Analysis",
            "date_modified": "2025-12-31T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/foundations/recurrences",
            "content_html": "Recursive and divide-and-conquer algorithms describe their own running time with a recurrence: $T(n)$ in terms of $T$ on smaller inputs. We solve recurrences three ways — drawing the recursion tree, guessing-and-verifying by induction, and applying the Master Theorem — using merge sort as the running example.\n",
            "url": "https://notes.amittai.studio/algorithms/foundations/recurrences",
            "title": "Recurrences and the Master Theorem",
            "date_modified": "2025-12-30T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/divide-and-conquer/mergesort",
            "content_html": "Divide and conquer breaks a problem into smaller copies of itself, solves them recursively, and stitches the answers together. We meet the paradigm through mergesort — its merge step, its loop-invariant proof, and the recursion tree that pins its cost at $\\Theta(n\\log n)$ — then glimpse Karatsuba multiplication as a second example of the same idea.",
            "url": "https://notes.amittai.studio/algorithms/divide-and-conquer/mergesort",
            "title": "Divide and Conquer & Mergesort",
            "date_modified": "2025-12-29T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/divide-and-conquer/quicksort",
            "content_html": "Quicksort sorts in place by partitioning around a pivot and recursing on each side. We give Lomuto and Hoare partitioning with a correctness invariant, see why a bad pivot costs $\\Theta(n^2)$ while a balanced one gives $\\Theta(n\\log n)$, and prove that randomizing the pivot makes the expected cost $\\Theta(n\\log n)$ on every input.",
            "url": "https://notes.amittai.studio/algorithms/divide-and-conquer/quicksort",
            "title": "Quicksort",
            "date_modified": "2025-12-28T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/divide-and-conquer/selection",
            "content_html": "Finding the $k$-th smallest element looks like it should require sorting, but it does not. Quickselect adapts quicksort's partition to recurse on just one side, achieving expected $O(n)$. The median-of-medians algorithm guarantees a good pivot with the groups-of-five trick, pushing the worst case down to a provable $O(n)$.",
            "url": "https://notes.amittai.studio/algorithms/divide-and-conquer/selection",
            "title": "Linear-Time Selection",
            "date_modified": "2025-12-27T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sorting/heaps-and-heapsort",
            "content_html": "A binary heap is a tree we store flat in an array, with index arithmetic standing in for pointers. We build the max-heap property bottom-up in $O(n)$ time, sort in place in $\\Theta(n\\log n)$ by repeatedly extracting the maximum, and reuse the same structure to implement a priority queue.",
            "url": "https://notes.amittai.studio/algorithms/sorting/heaps-and-heapsort",
            "title": "Heaps and Heapsort",
            "date_modified": "2025-12-26T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sorting/sorting-lower-bounds",
            "content_html": "Every sort we have seen runs in $\\Omega(n\\log n)$, and that is no accident. Modeling a sort as a decision tree of comparisons, we show any such tree must have $n!$ leaves, forcing height $\\ge \\log_2(n!) = \\Omega(n\\log n)$ — a worst-case bound no comparison sort can ever beat.",
            "url": "https://notes.amittai.studio/algorithms/sorting/sorting-lower-bounds",
            "title": "Lower Bounds for Comparison Sorting",
            "date_modified": "2025-12-25T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sorting/linear-time-sorting",
            "content_html": "The $\\Omega(n\\log n)$ barrier only binds algorithms that compare. By instead using keys as array indices we slip past it: counting sort runs in $\\Theta(n+k)$ and is stable, radix sort layers it digit by digit, and bucket sort averages $\\Theta(n)$ on uniform data. We see exactly when each applies.",
            "url": "https://notes.amittai.studio/algorithms/sorting/linear-time-sorting",
            "title": "Sorting in Linear Time",
            "date_modified": "2025-12-24T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/data-structures/elementary-structures",
            "content_html": "Every container is built one of two ways: **contiguous** in an array, or **linked** through pointers. We trade cache-friendly random access against $O(1)$ splicing, derive the **amortized $O(1)$** append of a doubling dynamic array, and assemble the two ordered access disciplines — the LIFO **stack** and the FIFO **queue** (with its generalization, the **deque**) — on top of both.",
            "url": "https://notes.amittai.studio/algorithms/data-structures/elementary-structures",
            "title": "Elementary Data Structures",
            "date_modified": "2025-12-23T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/data-structures/hash-tables",
            "content_html": "A hash table implements the dictionary — insert, search, delete — in expected $O(1)$ time by scattering keys across an array with a hash function. We build up from direct addressing, handle collisions by chaining and by open addressing, analyze the load factor $\\alpha$, and see how universal hashing earns its expected-time guarantee against every input.",
            "url": "https://notes.amittai.studio/algorithms/data-structures/hash-tables",
            "title": "Hash Tables",
            "date_modified": "2025-12-22T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/data-structures/binary-search-trees",
            "content_html": "A binary search tree keeps keys ordered so that every operation follows a single root-to-leaf path. We state the BST property, give search and insert, find minimum, maximum, and successor, see that an inorder walk emits the keys in sorted order, and confront the catch — every operation costs $O(h)$, and a carelessly built tree degrades to height $h = \\Theta(n)$, motivating balance.",
            "url": "https://notes.amittai.studio/algorithms/data-structures/binary-search-trees",
            "title": "Binary Search Trees",
            "date_modified": "2025-12-21T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/data-structures/avl-trees",
            "content_html": "An AVL tree is the first balanced BST: at every node the two subtrees' heights differ by at most $1$. A Fibonacci-style minimal-node argument forces height $h \\le 1.44\\log_2 n = O(\\log n)$, so search, insert, and delete are all $O(\\log n)$. Insertion rebalances with at most one of four rotation cases (LL, RR, LR, RL); deletion may rotate all the way to the root.",
            "url": "https://notes.amittai.studio/algorithms/data-structures/avl-trees",
            "title": "AVL Trees",
            "date_modified": "2025-12-20T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/data-structures/balanced-trees",
            "content_html": "An ordinary BST can degrade to height $\\Theta(n)$; balanced search trees guarantee $h = O(\\log n)$ by maintaining invariants and repairing them after every update. We meet rotations, the local restructuring primitive, then red-black trees, whose color invariants force logarithmic height, and finally B-trees, which trade tall-and-thin for short-and-wide to win on disk.",
            "url": "https://notes.amittai.studio/algorithms/data-structures/balanced-trees",
            "title": "Balanced Search Trees",
            "date_modified": "2025-12-19T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/data-structures/union-find",
            "content_html": "The disjoint-set data structure tracks a partition of elements into groups, answering \"are these two in the same group?\" and merging groups on demand. A forest of parent pointers, sped up by union by rank and path compression, drives every operation to near-constant $O(\\alpha(n))$ amortized time — the engine behind connectivity queries and Kruskal's minimum spanning tree.",
            "url": "https://notes.amittai.studio/algorithms/data-structures/union-find",
            "title": "Disjoint Sets (Union-Find)",
            "date_modified": "2025-12-18T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/data-structures/fenwick-and-segment-trees",
            "content_html": "A prefix-sum array answers a range sum in $O(1)$ but pays $O(n)$ per update; a plain array updates in $O(1)$ but pays $O(n)$ per range sum. Fenwick and segment trees give us _both_ in $O(\\log n)$. The Fenwick (binary indexed) tree is a tiny array keyed by the low bit; the segment tree is a general balanced tree over canonical ranges that handles any associative aggregate and, with lazy propagation, range updates too.",
            "url": "https://notes.amittai.studio/algorithms/data-structures/fenwick-and-segment-trees",
            "title": "Fenwick & Segment Trees",
            "date_modified": "2025-12-17T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sequences/two-pointers-and-windows",
            "content_html": "A family of array idioms that collapse an obvious $O(n^2)$ scan into a single $O(n)$ pass by maintaining an invariant as indices move. We meet two pointers (converging on a sorted array, and a fast/slow pair for in-place rewriting), the sliding window (fixed and variable size, amortized $O(n)$), and prefix sums, which answer any range-sum in $O(1)$ and count subarrays summing to $k$.",
            "url": "https://notes.amittai.studio/algorithms/sequences/two-pointers-and-windows",
            "title": "Two Pointers, Sliding Windows & Prefix Sums",
            "date_modified": "2025-12-16T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sequences/monotonic-stacks",
            "content_html": "A **monotonic stack** keeps its contents sorted by popping every element that would break the order before each push — turning a family of \"previous/next greater (or smaller) element\" questions into a single $O(n)$ scan. We derive the next-greater-element routine and its amortized analysis, fuse two such scans to measure the **largest rectangle in a histogram** in linear time, and extend the idea to a **monotonic deque** that streams the **sliding-window maximum** in $O(n)$.",
            "url": "https://notes.amittai.studio/algorithms/sequences/monotonic-stacks",
            "title": "Monotonic Stacks & Queues",
            "date_modified": "2025-12-15T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sequences/binary-search-on-the-answer",
            "content_html": "Binary search is not really about arrays — it is about locating the boundary of a **monotone predicate** $p(x)$ in $O(\\log(\\text{range}))$ probes. We first pin down the half-open `while (lo < hi)` template for $\\textsc{lower\\_bound}$ and $\\textsc{upper\\_bound}$, then generalize to \"binary search on the answer\": whenever feasibility is monotone in a numeric parameter, we binary search the parameter itself, calling a feasibility check at each step.",
            "url": "https://notes.amittai.studio/algorithms/sequences/binary-search-on-the-answer",
            "title": "Binary Search on the Answer",
            "date_modified": "2025-12-14T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sequences/string-matching",
            "content_html": "Given a text $T$ of length $n$ and a pattern $P$ of length $m$, find every occurrence of $P$ in $T$. The naive scan costs $O(nm)$; we beat it three ways. Rabin–Karp uses a **rolling hash** to test alignments in $O(1)$ amortised each, with expected $O(n+m)$. KMP precomputes a **failure function** so the scan never re-reads a text character, for worst-case $O(n+m)$. The **Z-function** gives the same bound from a different angle and converts freely to KMP's table.",
            "url": "https://notes.amittai.studio/algorithms/sequences/string-matching",
            "title": "String Matching: Rabin–Karp, KMP & Z",
            "date_modified": "2025-12-13T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/sequences/tries",
            "content_html": "A **trie** stores a set of strings in a tree keyed by _characters_, so that insert, search, and prefix-test all run in $O(L)$ time — the length of the key, _independent of how many keys are stored_. Shared prefixes are stored once, which makes tries the natural structure for autocomplete, wildcard dictionaries, board word-search, and — over the alphabet $\\{0,1\\}$ — the maximum-XOR-pair problem.",
            "url": "https://notes.amittai.studio/algorithms/sequences/tries",
            "title": "Tries & Prefix Trees",
            "date_modified": "2025-12-12T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/representations-and-traversal",
            "content_html": "A graph captures _relationships_ — who connects to whom. We fix the vocabulary, weigh the two standard representations (adjacency list versus matrix), then meet the two explorations you'll use constantly: breadth-first search, which finds shortest paths by number of edges, and depth-first search, whose discovery and finish times reveal a graph's hidden structure. Both run in $O(V + E)$.",
            "url": "https://notes.amittai.studio/algorithms/graphs/representations-and-traversal",
            "title": "Graph Representations and Traversal",
            "date_modified": "2025-12-11T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/topological-sort-and-scc",
            "content_html": "Directed acyclic graphs model dependencies: tasks that must precede other tasks. A _topological order_ lays such a graph out in a line so every edge points forward, and depth-first finish times hand it to us almost for free. We then ask the harder question for graphs _with_ cycles: which vertices can reach each other? The answer is the strongly connected components, found by a two-pass DFS.",
            "url": "https://notes.amittai.studio/algorithms/graphs/topological-sort-and-scc",
            "title": "Topological Sort and Strong Connectivity",
            "date_modified": "2025-12-10T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/minimum-spanning-trees",
            "content_html": "Given a weighted network, how do we connect everything as cheaply as possible? The answer is a minimum spanning tree. One lemma, the cut property, justifies _every_ correct MST algorithm, and from it two famous greedy methods fall out: Kruskal's, which grows a forest edge by edge with a union-find structure, and Prim's, which grows a single tree using a priority queue.",
            "url": "https://notes.amittai.studio/algorithms/graphs/minimum-spanning-trees",
            "title": "Minimum Spanning Trees",
            "date_modified": "2025-12-09T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/shortest-paths",
            "content_html": "Finding the cheapest route through a weighted network is one of the most-used algorithms in computing. A single operation — _relaxation_ — underlies them all. Dijkstra's algorithm solves the non-negative case greedily; Bellman-Ford handles negative edges and detects negative cycles; and Floyd-Warshall finds the shortest path between _every_ pair of vertices.",
            "url": "https://notes.amittai.studio/algorithms/graphs/shortest-paths",
            "title": "Shortest Paths",
            "date_modified": "2025-12-08T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/network-flow",
            "content_html": "How much can flow through a network from source to sink? Max-flow is a surprisingly general model — once you see a problem as flow, a whole toolbox opens up. We build flow networks, find maximum flows by repeatedly pushing along augmenting paths in the residual graph, prove the max-flow min-cut theorem, and watch bipartite matching fall out as a special case.",
            "url": "https://notes.amittai.studio/algorithms/graphs/network-flow",
            "title": "Network Flow",
            "date_modified": "2025-12-07T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/bridges-and-articulation-points",
            "content_html": "A **bridge** is an edge whose removal disconnects the graph; an **articulation point** is a vertex whose removal does. Both are single points of failure in a network. A single depth-first search computes discovery times and **low-links**, and two local criteria — $low[v] > disc[u]$ for bridges, $low[v] \\ge disc[u]$ for cut vertices — find them all in $O(V+E)$.",
            "url": "https://notes.amittai.studio/algorithms/graphs/bridges-and-articulation-points",
            "title": "Bridges & Articulation Points",
            "date_modified": "2025-12-06T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/lowest-common-ancestor",
            "content_html": "Given a rooted tree, the lowest common ancestor of $u$ and $v$ is the deepest node that is an ancestor of both. A naive walk answers one query in $O(h)$; **binary lifting** precomputes the $2^k$-th ancestor of every node in $O(n\\log n)$, then answers $k$-th-ancestor and LCA queries in $O(\\log n)$ each. We derive both jumps, apply them to tree distance, and compare against the Euler-tour + RMQ and Tarjan offline alternatives.",
            "url": "https://notes.amittai.studio/algorithms/graphs/lowest-common-ancestor",
            "title": "Lowest Common Ancestor & Binary Lifting",
            "date_modified": "2025-12-05T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/two-sat",
            "content_html": "A boolean formula whose every clause has exactly two literals can be solved in _linear_ time — even though its three-literal cousin is NP-complete. The trick is to read each clause as a pair of implications, build a directed graph on the $2n$ literals, and ask a question we already know how to answer: which literals share a strongly connected component? The formula is satisfiable iff no variable lands in the same SCC as its own negation, and the SCCs' topological order hands us a satisfying assignment for free.",
            "url": "https://notes.amittai.studio/algorithms/graphs/two-sat",
            "title": "2-SAT via Implication Graphs",
            "date_modified": "2025-12-04T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/graphs/eulerian-tours",
            "content_html": "An **Eulerian tour** uses every _edge_ of a graph exactly once. We give the exact parity and balance conditions under which one exists (even degree for undirected graphs, in-degree equal to out-degree for directed) and Hierholzer's $O(E)$ algorithm that constructs one by splicing closed sub-tours. We contrast this sharply with the **Hamiltonian** problem (visit every _vertex_ once), which is NP-complete: visiting edges is easy, visiting vertices is hard.",
            "url": "https://notes.amittai.studio/algorithms/graphs/eulerian-tours",
            "title": "Eulerian Tours",
            "date_modified": "2025-12-03T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/greedy/the-greedy-method",
            "content_html": "A greedy algorithm builds a solution one locally-best choice at a time and never looks back. We pin down the two properties that make this work — the greedy-choice property and optimal substructure — prove the canonical activity-selection algorithm correct with an exchange argument, watch greedy fail spectacularly on the 0/1 knapsack, and glimpse matroids as the theory that says exactly when greed is good.",
            "url": "https://notes.amittai.studio/algorithms/greedy/the-greedy-method",
            "title": "The Greedy Method",
            "date_modified": "2025-12-02T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/greedy/scheduling-and-intervals",
            "content_html": "Three classic scheduling problems all yield to greedy algorithms — and all three turn on a single design decision: which key to sort by. Interval scheduling sorts by **finish** time to pack the most compatible jobs; interval partitioning sorts by **start** time and proves the rooms needed equal the maximum overlap **depth**; minimizing maximum lateness sorts by **deadline** and is justified by an adjacent-swap exchange argument.",
            "url": "https://notes.amittai.studio/algorithms/greedy/scheduling-and-intervals",
            "title": "Scheduling & Interval Partitioning",
            "date_modified": "2025-12-01T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/greedy/huffman-codes",
            "content_html": "Huffman coding is the greedy method's most beautiful application: it builds a provably optimal prefix-free binary code by repeatedly merging the two least frequent symbols. We develop prefix-free codes as binary trees, give the algorithm with a priority queue, build a Huffman tree from example frequencies, prove optimality with the same greedy-choice-plus-substructure argument, and pin the running time at $O(n\\log n)$.",
            "url": "https://notes.amittai.studio/algorithms/greedy/huffman-codes",
            "title": "Huffman Codes",
            "date_modified": "2025-11-30T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/greedy/matroids",
            "content_html": "The capstone of the greedy module: _why_ and _when_ a greedy algorithm is provably optimal. We recap the two correctness templates — **greedy-stays-ahead** and the **exchange argument** — then meet the **matroid** $M=(S,\\mathcal{I})$, an abstraction whose **exchange property** is exactly the structure greedy needs. The matroid–greedy theorem says sorting by weight and taking what stays independent yields a maximum-weight basis _if and only if_ the structure is a matroid. Kruskal's MST is the canonical instance; 0/1 knapsack and TSP are the canonical failures.",
            "url": "https://notes.amittai.studio/algorithms/greedy/matroids",
            "title": "Matroids & Exchange Arguments",
            "date_modified": "2025-11-29T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/principles",
            "content_html": "Dynamic programming is recursion with memory: when a recursive solution re-solves the same subproblems again and again, we solve each one once and store the answer. We pin down the two structural conditions that make this work — overlapping subproblems and optimal substructure — contrast top-down memoization with bottom-up tabulation, and distil the whole method into a five-step recipe.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/principles",
            "title": "Principles of Dynamic Programming",
            "date_modified": "2025-11-28T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/sequence-dp",
            "content_html": "Two strings can be compared by asking how much of one survives inside the other. The longest common subsequence (LCS) and edit distance are the two classic answers, and they are the _same_ dynamic program wearing different costs. We derive the LCS recurrence by examining the last characters, fill a worked DP table, reconstruct the subsequence, and then show edit distance as the identical $\\Theta(mn)$ pattern.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/sequence-dp",
            "title": "Sequence Alignment & LCS",
            "date_modified": "2025-11-27T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/longest-increasing-subsequence",
            "content_html": "Given a sequence of numbers, how long is its longest strictly increasing subsequence? A first dynamic program indexes subproblems by the element each subsequence _ends at_, giving an $O(n^2)$ solution with parent-pointer reconstruction. A sharper idea, the patience-sorting _tails_ array searched by binary search, drops the time to $O(n\\log n)$. We then fold in the variants: non-decreasing, counting, Russian-doll envelopes, and bitonic.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/longest-increasing-subsequence",
            "title": "Longest Increasing Subsequence",
            "date_modified": "2025-11-26T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/knapsack",
            "content_html": "We start from $\\textsc{Subset-sum}$ — does some sublist hit a target $t$? — and its include/exclude recurrence over a boolean table $A(i, u)$, then bolt on values to get 0/1 knapsack as the same machine with $\\lor$ promoted to $\\max$. We fill both tables, recover the chosen items, and confront the surprise that the $\\Theta(nt)$ running time is only _pseudo-polynomial_ — exponential in the bit length $b$, and unimprovable unless $\\mathrm{P}=\\mathrm{NP}$ since subset-sum is $\\textsc{NP-complete}$. The fractional variant reveals the sharp line between greedy and dynamic programming.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/knapsack",
            "title": "Knapsack & Subset Problems",
            "date_modified": "2025-11-25T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/coin-change-and-unbounded",
            "content_html": "The previous lesson let each item be taken at most once. Drop that cap — items may be reused _any number of times_ — and the 0/1 knapsack collapses from a two-dimensional table to a one-dimensional one, because there is no longer a prefix of \"already-used\" items to track. We meet **unbounded knapsack**, then its most famous instance, **coin change**: the minimum-coins recurrence $C[a] = 1 + \\min_c C[a-c]$, and the counting variant where the _order of the loops_ decides whether you count unordered combinations or ordered sequences — the classic bug. Greed fails in general but works for canonical coin systems.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/coin-change-and-unbounded",
            "title": "Coin Change & Unbounded Knapsack",
            "date_modified": "2025-11-24T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/interval-dp",
            "content_html": "Many problems ask for the best way to combine a contiguous range of items, and the answer is a dynamic program over subintervals $[i,j]$ that chooses a split point $k$. We derive the pattern from matrix-chain multiplication — parenthesising a product to minimize scalar multiplications in $O(n^3)$ — distil it into a reusable template filled by increasing interval length, and then meet its sharpest variant: the \"last operation\" trick behind Burst Balloons and cutting a stick, where fixing the _last_ move (not the first) makes the two sides independent.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/interval-dp",
            "title": "Interval DP",
            "date_modified": "2025-11-23T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/tree-dp",
            "content_html": "When the subproblems of a dynamic program are _rooted subtrees_, a single post-order DFS solves the whole thing in $O(n)$: each node combines the already-computed answers of its children. We meet the archetype — maximum-weight independent set on a tree — then the \"path through a node\" pattern behind tree diameter and maximum path sum, and finally **rerooting**, which computes a per-node answer for _every_ node as root in $O(n)$ with two passes.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/tree-dp",
            "title": "Dynamic Programming on Trees",
            "date_modified": "2025-11-22T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/bitmask-dp",
            "content_html": "When a subproblem depends not on an index or a prefix but on _which subset_ of a small ground set has been used, we can encode that subset as the bits of an integer and index a DP table by it. With $n \\le \\sim 20$ the $2^n$ subsets fit in a table, turning $\\Theta(n!)$ brute force into $O(2^n \\cdot \\text{poly}(n))$. We meet the bit tricks, the Held–Karp TSP archetype, assignment by mask, subset-sum partitioning, and submask enumeration with its $3^n$ bound.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/bitmask-dp",
            "title": "Bitmask DP",
            "date_modified": "2025-11-21T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/dp-optimizations",
            "content_html": "A correct DP recurrence is only half the battle; its naive evaluation is often a factor of $n$ slower than necessary. This capstone surveys five techniques, monotonic-queue, the convex hull trick, divide-and-conquer optimization, Knuth's optimization, and SOS DP, that each exploit _structure in the transition_ (a sliding window, linear costs, monotone optimal splits, the quadrangle inequality, or subset lattices) to shave an $O(n)$, $O(\\log n)$, or worse factor off the running time.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/dp-optimizations",
            "title": "DP Optimizations",
            "date_modified": "2025-11-20T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/dynamic-programming/dp-on-graphs",
            "content_html": "Many graph algorithms are dynamic programs in disguise: the subproblem is the _best value reachable under a restricted resource_ — intermediate vertices allowed, edges allowed, or a topological prefix — and edge _relaxation_ is the DP transition. We frame Floyd–Warshall as the archetype ($O(V^3)$ all-pairs shortest paths), Bellman–Ford as a DP over path length (the at-most-$K$-stops variant), DAG-DP in topological order ($O(V+E)$), and Warshall's transitive closure as the boolean analog.",
            "url": "https://notes.amittai.studio/algorithms/dynamic-programming/dp-on-graphs",
            "title": "Dynamic Programming on Graphs",
            "date_modified": "2025-11-19T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/backtracking/backtracking-fundamentals",
            "content_html": "Backtracking builds a solution one choice at a time and abandons a partial solution the moment it cannot be completed, exploring a state-space tree by depth-first search. We meet the universal choose/explore/un-choose template, derive the canonical enumerations — subsets ($2^n$), permutations ($n!$), and combinations ($\\binom{n}{k}$) — handle duplicate elements by skipping equal siblings, and see how pruning turns an exponential search into a tractable one.",
            "url": "https://notes.amittai.studio/algorithms/backtracking/backtracking-fundamentals",
            "title": "Backtracking: Subsets, Permutations & Combinations",
            "date_modified": "2025-11-18T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/backtracking/constraint-search",
            "content_html": "Many hard puzzles are **constraint satisfaction problems**: assign each variable a value from its domain so that every constraint holds. Backtracking solves them by assigning variables one at a time and rejecting a partial assignment the instant a constraint breaks. We make the rejection cheap — $O(1)$ conflict checks for N-Queens via column and diagonal sets — and prune harder with **forward checking**, **MRV** ordering, and **constraint propagation**, which is what lets an exponential search actually finish.",
            "url": "https://notes.amittai.studio/algorithms/backtracking/constraint-search",
            "title": "Constraint Search: N-Queens & Sudoku",
            "date_modified": "2025-11-17T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/backtracking/branch-and-bound",
            "content_html": "Plain backtracking prunes a search tree by _feasibility_; for _optimization_ problems we can prune far more aggressively by _value_. **Branch and bound** keeps the best complete solution found so far and discards any partial solution whose optimistic bound cannot beat it. **Meet in the middle** splits the instance in two, enumerates each half, and recombines by binary search — turning $2^n$ into $O(2^{n/2}\\,n)$ and pushing exact search out to $n \\approx 40$.",
            "url": "https://notes.amittai.studio/algorithms/backtracking/branch-and-bound",
            "title": "Branch & Bound and Meet in the Middle",
            "date_modified": "2025-11-16T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/mathematical-algorithms/number-theory-basics",
            "content_html": "This lesson opens the mathematical-algorithms module with the bedrock of computational number theory. We prove Euclid's recurrence $\\gcd(a,b)=\\gcd(b,\\,a\\bmod b)$ and its $O(\\log\\min(a,b))$ running time, extend it to recover Bézout coefficients $x,y$ with $ax+by=\\gcd(a,b)$, and build modular arithmetic on residue classes — including when a modular inverse $a^{-1}\\bmod m$ exists and how to compute it.",
            "url": "https://notes.amittai.studio/algorithms/mathematical-algorithms/number-theory-basics",
            "title": "Number Theory: GCD & Modular Arithmetic",
            "date_modified": "2025-11-15T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/mathematical-algorithms/modular-exponentiation-and-primality",
            "content_html": "Computing $a^n \\bmod m$ naively costs $n$ multiplications; **repeated squaring** does it in $O(\\log n)$ by reading the bits of the exponent. We use this routine to state **Fermat's little theorem** (and the modular inverse it gives), then to test primality — trial division, the probabilistic **Fermat** and **Miller–Rabin** tests, and the deterministic witness set that settles primality for every 64-bit number.",
            "url": "https://notes.amittai.studio/algorithms/mathematical-algorithms/modular-exponentiation-and-primality",
            "title": "Modular Exponentiation & Primality",
            "date_modified": "2025-11-14T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/mathematical-algorithms/sieve-and-factorization",
            "content_html": "The previous lesson tested one number for primality; here we ask for _all_ primes up to $n$ at once. The **sieve of Eratosthenes** cross-cuts composites in $O(n\\log\\log n)$, and a **linear sieve** does it in $O(n)$ while recording each number's **smallest prime factor**, which then factors any $x \\le n$ in $O(\\log x)$. From a factorization $x = \\prod p_i^{e_i}$ the multiplicative functions $\\tau$, $\\sigma$, and Euler's totient $\\varphi$ fall out immediately.",
            "url": "https://notes.amittai.studio/algorithms/mathematical-algorithms/sieve-and-factorization",
            "title": "Sieves & Factorization",
            "date_modified": "2025-11-13T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/mathematical-algorithms/combinatorics",
            "content_html": "Counting is the arithmetic of finite sets. We build up from permutations $n!$ and combinations $\\binom{n}{k}$, prove Pascal's rule by a bijection, and count multisets with stars and bars. The practical core is computing $\\binom{n}{k}\\bmod p$ in $O(1)$ from precomputed factorials and inverse factorials. We close with inclusion–exclusion and the Chinese Remainder Theorem, both of which lean on the modular inverse from the previous lesson.",
            "url": "https://notes.amittai.studio/algorithms/mathematical-algorithms/combinatorics",
            "title": "Combinatorics & Counting",
            "date_modified": "2025-11-12T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/computational-geometry/geometric-primitives",
            "content_html": "Computational geometry is built on a single reliable primitive — the **orientation test**, a sign of a cross product that tells whether three points turn left, right, or lie collinear. From points-as-vectors and the dot and cross products we derive orientation, segment intersection, the shoelace area formula, and point-in-polygon tests, keeping all arithmetic **exact and integer** so that no floating-point rounding can corrupt a sign.",
            "url": "https://notes.amittai.studio/algorithms/computational-geometry/geometric-primitives",
            "title": "Geometric Primitives & Orientation",
            "date_modified": "2025-11-11T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/computational-geometry/convex-hull",
            "content_html": "The convex hull is the smallest convex polygon enclosing a point set — the rubber band snapped around the nails. We build it with Andrew's monotone chain, sorting by $(x,y)$ and sweeping a lower and upper hull while popping any non-left turn via the orientation primitive, in $O(n\\log n)$. A reduction from sorting shows that bound is optimal, and the hull unlocks diameter, smallest enclosing rectangle, and more through rotating calipers.",
            "url": "https://notes.amittai.studio/algorithms/computational-geometry/convex-hull",
            "title": "Convex Hull",
            "date_modified": "2025-11-10T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/computational-geometry/sweep-line",
            "content_html": "The plane-sweep paradigm turns a static $2$-D geometry problem into a dynamic $1$-D ordered-set problem: a vertical line sweeps left to right, stopping at an $x$-sorted **event queue** while a balanced-BST **status structure** tracks the objects it currently crosses, ordered by $y$. We derive Bentley–Ottmann segment intersection in $O((n+k)\\log n)$, recover closest-pair in $O(n\\log n)$, and reduce skyline, rectangle-area, and overlap problems to $\\pm1$ event sweeps.",
            "url": "https://notes.amittai.studio/algorithms/computational-geometry/sweep-line",
            "title": "Sweep-Line Algorithms",
            "date_modified": "2025-11-09T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/intractability/p-np-reductions",
            "content_html": "Most problems we have met so far have fast algorithms. A vast and important family seemingly does not. This lesson builds the vocabulary for that divide: decision problems, the class $\\mathsf{P}$ of problems we can solve quickly, the class $\\mathsf{NP}$ of problems whose solutions we can _check_ quickly, and polynomial-time reductions, the tool that lets us compare the difficulty of two problems without solving either.",
            "url": "https://notes.amittai.studio/algorithms/intractability/p-np-reductions",
            "title": "P, NP, and Reductions",
            "date_modified": "2025-11-08T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/intractability/np-completeness",
            "content_html": "Some problems in $\\mathsf{NP}$ are universally hardest: every other problem in $\\mathsf{NP}$ reduces to them. This lesson defines $\\mathsf{NP}$-hard and $\\mathsf{NP}$-complete, states the Cook–Levin theorem that anchors the whole edifice on **SAT**, walks the web of reductions that grows from it, and gives the four-step recipe for proving a brand-new problem $\\mathsf{NP}$-complete.",
            "url": "https://notes.amittai.studio/algorithms/intractability/np-completeness",
            "title": "NP-Completeness",
            "date_modified": "2025-11-07T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        },
        {
            "id": "https://notes.amittai.studio/algorithms/intractability/coping-with-hardness",
            "content_html": "Proving a problem $\\mathsf{NP}$-hard is the beginning, not the end. The world still needs answers. This lesson surveys the four honest responses to hardness: approximation algorithms with a provable ratio (worked through a 2-approximation for vertex cover), heuristics and local search, exact exponential methods like branch and bound, and exploiting special structure in the instances you actually face.",
            "url": "https://notes.amittai.studio/algorithms/intractability/coping-with-hardness",
            "title": "Coping with NP-Hardness",
            "date_modified": "2025-11-06T00:00:00.000Z",
            "author": {
                "name": "Amittai Siavava",
                "url": "https://amittai.studio"
            }
        }
    ]
}