[{"data":1,"prerenderedAt":4807},["ShallowReactive",2],{"nav:algorithms":3,"lesson:\u002Falgorithms\u002Fdata-structures\u002Fbinary-search-trees":374,"course-wordcounts":4675,"ref-card-index":4731},[4,28,50,71,120,152,205,230,286,306,331,352],{"module":5,"moduleNumber":6,"slug":7,"lessons":8},"Foundations",1,"foundations",[9,15,21],{"title":10,"path":11,"lessonNumber":6,"topics":12,"summary":14},"What Is an Algorithm?","\u002Falgorithms\u002Ffoundations\u002Fwhat-is-an-algorithm",[5,13],"Correctness & Induction","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",{"title":16,"path":17,"lessonNumber":18,"topics":19,"summary":20},"Asymptotic Analysis","\u002Falgorithms\u002Ffoundations\u002Fasymptotic-analysis",2,[16],"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",{"title":22,"path":23,"lessonNumber":24,"topics":25,"summary":27},"Recurrences and the Master Theorem","\u002Falgorithms\u002Ffoundations\u002Frecurrences",3,[26],"Recurrences","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",{"module":29,"moduleNumber":18,"slug":30,"lessons":31},"Divide & Conquer","divide-and-conquer",[32,38,44],{"title":33,"path":34,"lessonNumber":6,"topics":35,"summary":37},"Divide and Conquer & Mergesort","\u002Falgorithms\u002Fdivide-and-conquer\u002Fmergesort",[29,36],"Comparison Sorting","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.",{"title":39,"path":40,"lessonNumber":18,"topics":41,"summary":43},"Quicksort","\u002Falgorithms\u002Fdivide-and-conquer\u002Fquicksort",[36,42],"Probabilistic Analysis","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.",{"title":45,"path":46,"lessonNumber":24,"topics":47,"summary":49},"Linear-Time Selection","\u002Falgorithms\u002Fdivide-and-conquer\u002Fselection",[48,29],"Order Statistics","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)$.",{"module":51,"moduleNumber":24,"slug":52,"lessons":53},"Sorting & Order Statistics","sorting",[54,60,65],{"title":55,"path":56,"lessonNumber":6,"topics":57,"summary":59},"Heaps and Heapsort","\u002Falgorithms\u002Fsorting\u002Fheaps-and-heapsort",[58,36],"Heaps","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.",{"title":61,"path":62,"lessonNumber":18,"topics":63,"summary":64},"Lower Bounds for Comparison Sorting","\u002Falgorithms\u002Fsorting\u002Fsorting-lower-bounds",[36],"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.",{"title":66,"path":67,"lessonNumber":24,"topics":68,"summary":70},"Sorting in Linear Time","\u002Falgorithms\u002Fsorting\u002Flinear-time-sorting",[69],"Linear-Time Sorting","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.",{"module":72,"moduleNumber":73,"slug":74,"lessons":75},"Data Structures",4,"data-structures",[76,82,88,93,99,105,113],{"title":77,"path":78,"lessonNumber":6,"topics":79,"summary":81},"Elementary Data Structures","\u002Falgorithms\u002Fdata-structures\u002Felementary-structures",[80],"Linear Structures","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.",{"title":83,"path":84,"lessonNumber":18,"topics":85,"summary":87},"Hash Tables","\u002Falgorithms\u002Fdata-structures\u002Fhash-tables",[86],"Hashing","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.",{"title":89,"path":90,"lessonNumber":24,"topics":91,"summary":92},"Binary Search Trees","\u002Falgorithms\u002Fdata-structures\u002Fbinary-search-trees",[89],"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.",{"title":94,"path":95,"lessonNumber":73,"topics":96,"summary":98},"AVL Trees","\u002Falgorithms\u002Fdata-structures\u002Favl-trees",[97],"Balanced Trees","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.",{"title":100,"path":101,"lessonNumber":102,"topics":103,"summary":104},"Balanced Search Trees","\u002Falgorithms\u002Fdata-structures\u002Fbalanced-trees",5,[97],"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.",{"title":106,"path":107,"lessonNumber":108,"topics":109,"summary":112},"Disjoint Sets (Union-Find)","\u002Falgorithms\u002Fdata-structures\u002Funion-find",6,[110,111],"Disjoint Sets","Amortized Analysis","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.",{"title":114,"path":115,"lessonNumber":116,"topics":117,"summary":119},"Fenwick & Segment Trees","\u002Falgorithms\u002Fdata-structures\u002Ffenwick-and-segment-trees",7,[118],"Range Queries","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.",{"module":121,"moduleNumber":102,"slug":122,"lessons":123},"Sequences & Strings","sequences",[124,130,135,141,147],{"title":125,"path":126,"lessonNumber":6,"topics":127,"summary":129},"Two Pointers, Sliding Windows & Prefix Sums","\u002Falgorithms\u002Fsequences\u002Ftwo-pointers-and-windows",[128],"Array Techniques","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\u002Fslow 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$.",{"title":131,"path":132,"lessonNumber":18,"topics":133,"summary":134},"Monotonic Stacks & Queues","\u002Falgorithms\u002Fsequences\u002Fmonotonic-stacks",[128],"A **monotonic stack** keeps its contents sorted by popping every element that would break the order before each push — turning a family of \"previous\u002Fnext 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)$.",{"title":136,"path":137,"lessonNumber":24,"topics":138,"summary":140},"Binary Search on the Answer","\u002Falgorithms\u002Fsequences\u002Fbinary-search-on-the-answer",[139],"Searching","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 \u003C 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.",{"title":142,"path":143,"lessonNumber":73,"topics":144,"summary":146},"String Matching: Rabin–Karp, KMP & Z","\u002Falgorithms\u002Fsequences\u002Fstring-matching",[145],"Strings","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.",{"title":148,"path":149,"lessonNumber":102,"topics":150,"summary":151},"Tries & Prefix Trees","\u002Falgorithms\u002Fsequences\u002Ftries",[145],"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.",{"module":153,"moduleNumber":108,"slug":154,"lessons":155},"Graphs","graphs",[156,163,168,173,178,183,188,193,199],{"title":157,"path":158,"lessonNumber":6,"topics":159,"summary":162},"Graph Representations and Traversal","\u002Falgorithms\u002Fgraphs\u002Frepresentations-and-traversal",[160,161],"Graph Representations","Graph Traversal","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)$.",{"title":164,"path":165,"lessonNumber":18,"topics":166,"summary":167},"Topological Sort and Strong Connectivity","\u002Falgorithms\u002Fgraphs\u002Ftopological-sort-and-scc",[161],"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.",{"title":169,"path":170,"lessonNumber":24,"topics":171,"summary":172},"Minimum Spanning Trees","\u002Falgorithms\u002Fgraphs\u002Fminimum-spanning-trees",[169],"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.",{"title":174,"path":175,"lessonNumber":73,"topics":176,"summary":177},"Shortest Paths","\u002Falgorithms\u002Fgraphs\u002Fshortest-paths",[174],"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.",{"title":179,"path":180,"lessonNumber":102,"topics":181,"summary":182},"Network Flow","\u002Falgorithms\u002Fgraphs\u002Fnetwork-flow",[179],"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.",{"title":184,"path":185,"lessonNumber":108,"topics":186,"summary":187},"Bridges & Articulation Points","\u002Falgorithms\u002Fgraphs\u002Fbridges-and-articulation-points",[153],"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)$.",{"title":189,"path":190,"lessonNumber":116,"topics":191,"summary":192},"Lowest Common Ancestor & Binary Lifting","\u002Falgorithms\u002Fgraphs\u002Flowest-common-ancestor",[153],"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.",{"title":194,"path":195,"lessonNumber":196,"topics":197,"summary":198},"2-SAT via Implication Graphs","\u002Falgorithms\u002Fgraphs\u002Ftwo-sat",8,[153],"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.",{"title":200,"path":201,"lessonNumber":202,"topics":203,"summary":204},"Eulerian Tours","\u002Falgorithms\u002Fgraphs\u002Feulerian-tours",9,[153],"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.",{"module":206,"moduleNumber":116,"slug":207,"lessons":208},"Greedy Algorithms","greedy",[209,214,220,225],{"title":210,"path":211,"lessonNumber":6,"topics":212,"summary":213},"The Greedy Method","\u002Falgorithms\u002Fgreedy\u002Fthe-greedy-method",[206],"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\u002F1 knapsack, and glimpse matroids as the theory that says exactly when greed is good.",{"title":215,"path":216,"lessonNumber":18,"topics":217,"summary":219},"Scheduling & Interval Partitioning","\u002Falgorithms\u002Fgreedy\u002Fscheduling-and-intervals",[218],"Greedy","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.",{"title":221,"path":222,"lessonNumber":24,"topics":223,"summary":224},"Huffman Codes","\u002Falgorithms\u002Fgreedy\u002Fhuffman-codes",[206],"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)$.",{"title":226,"path":227,"lessonNumber":73,"topics":228,"summary":229},"Matroids & Exchange Arguments","\u002Falgorithms\u002Fgreedy\u002Fmatroids",[218],"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\u002F1 knapsack and TSP are the canonical failures.",{"module":231,"moduleNumber":196,"slug":232,"lessons":233},"Dynamic Programming","dynamic-programming",[234,239,245,250,255,260,265,270,275,280],{"title":235,"path":236,"lessonNumber":6,"topics":237,"summary":238},"Principles of Dynamic Programming","\u002Falgorithms\u002Fdynamic-programming\u002Fprinciples",[231,26],"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.",{"title":240,"path":241,"lessonNumber":18,"topics":242,"summary":244},"Sequence Alignment & LCS","\u002Falgorithms\u002Fdynamic-programming\u002Fsequence-dp",[231,243],"String Structures","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.",{"title":246,"path":247,"lessonNumber":24,"topics":248,"summary":249},"Longest Increasing Subsequence","\u002Falgorithms\u002Fdynamic-programming\u002Flongest-increasing-subsequence",[231],"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.",{"title":251,"path":252,"lessonNumber":73,"topics":253,"summary":254},"Knapsack & Subset Problems","\u002Falgorithms\u002Fdynamic-programming\u002Fknapsack",[231],"We start from $\\textsc{Subset-sum}$ — does some sublist hit a target $t$? — and its include\u002Fexclude recurrence over a boolean table $A(i, u)$, then bolt on values to get 0\u002F1 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.",{"title":256,"path":257,"lessonNumber":102,"topics":258,"summary":259},"Coin Change & Unbounded Knapsack","\u002Falgorithms\u002Fdynamic-programming\u002Fcoin-change-and-unbounded",[231],"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\u002F1 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.",{"title":261,"path":262,"lessonNumber":108,"topics":263,"summary":264},"Interval DP","\u002Falgorithms\u002Fdynamic-programming\u002Finterval-dp",[231],"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.",{"title":266,"path":267,"lessonNumber":116,"topics":268,"summary":269},"Dynamic Programming on Trees","\u002Falgorithms\u002Fdynamic-programming\u002Ftree-dp",[231],"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.",{"title":271,"path":272,"lessonNumber":196,"topics":273,"summary":274},"Bitmask DP","\u002Falgorithms\u002Fdynamic-programming\u002Fbitmask-dp",[231],"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.",{"title":276,"path":277,"lessonNumber":202,"topics":278,"summary":279},"DP Optimizations","\u002Falgorithms\u002Fdynamic-programming\u002Fdp-optimizations",[231],"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.",{"title":281,"path":282,"lessonNumber":283,"topics":284,"summary":285},"Dynamic Programming on Graphs","\u002Falgorithms\u002Fdynamic-programming\u002Fdp-on-graphs",10,[231],"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.",{"module":287,"moduleNumber":202,"slug":288,"lessons":289},"Backtracking & Search","backtracking",[290,296,301],{"title":291,"path":292,"lessonNumber":6,"topics":293,"summary":295},"Backtracking: Subsets, Permutations & Combinations","\u002Falgorithms\u002Fbacktracking\u002Fbacktracking-fundamentals",[294],"Backtracking","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\u002Fexplore\u002Fun-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.",{"title":297,"path":298,"lessonNumber":18,"topics":299,"summary":300},"Constraint Search: N-Queens & Sudoku","\u002Falgorithms\u002Fbacktracking\u002Fconstraint-search",[294],"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.",{"title":302,"path":303,"lessonNumber":24,"topics":304,"summary":305},"Branch & Bound and Meet in the Middle","\u002Falgorithms\u002Fbacktracking\u002Fbranch-and-bound",[294],"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\u002F2}\\,n)$ and pushing exact search out to $n \\approx 40$.",{"module":307,"moduleNumber":283,"slug":308,"lessons":309},"Mathematical Algorithms","mathematical-algorithms",[310,316,321,326],{"title":311,"path":312,"lessonNumber":6,"topics":313,"summary":315},"Number Theory: GCD & Modular Arithmetic","\u002Falgorithms\u002Fmathematical-algorithms\u002Fnumber-theory-basics",[314],"Number Theory","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.",{"title":317,"path":318,"lessonNumber":18,"topics":319,"summary":320},"Modular Exponentiation & Primality","\u002Falgorithms\u002Fmathematical-algorithms\u002Fmodular-exponentiation-and-primality",[314],"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.",{"title":322,"path":323,"lessonNumber":24,"topics":324,"summary":325},"Sieves & Factorization","\u002Falgorithms\u002Fmathematical-algorithms\u002Fsieve-and-factorization",[314],"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.",{"title":327,"path":328,"lessonNumber":73,"topics":329,"summary":330},"Combinatorics & Counting","\u002Falgorithms\u002Fmathematical-algorithms\u002Fcombinatorics",[314],"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.",{"module":332,"moduleNumber":333,"slug":334,"lessons":335},"Computational Geometry",11,"computational-geometry",[336,342,347],{"title":337,"path":338,"lessonNumber":6,"topics":339,"summary":341},"Geometric Primitives & Orientation","\u002Falgorithms\u002Fcomputational-geometry\u002Fgeometric-primitives",[340],"Geometry","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.",{"title":343,"path":344,"lessonNumber":18,"topics":345,"summary":346},"Convex Hull","\u002Falgorithms\u002Fcomputational-geometry\u002Fconvex-hull",[340],"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.",{"title":348,"path":349,"lessonNumber":24,"topics":350,"summary":351},"Sweep-Line Algorithms","\u002Falgorithms\u002Fcomputational-geometry\u002Fsweep-line",[340],"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.",{"module":353,"moduleNumber":354,"slug":355,"lessons":356},"Intractability",12,"intractability",[357,363,367],{"title":358,"path":359,"lessonNumber":6,"topics":360,"summary":362},"P, NP, and Reductions","\u002Falgorithms\u002Fintractability\u002Fp-np-reductions",[361],"NP-Completeness","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.",{"title":361,"path":364,"lessonNumber":18,"topics":365,"summary":366},"\u002Falgorithms\u002Fintractability\u002Fnp-completeness",[361],"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.",{"title":368,"path":369,"lessonNumber":24,"topics":370,"summary":373},"Coping with NP-Hardness","\u002Falgorithms\u002Fintractability\u002Fcoping-with-hardness",[371,372],"Approximation","Heuristics","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.",{"id":375,"title":89,"blurb":376,"body":377,"description":4635,"extension":4636,"meta":4637,"module":72,"navigation":4639,"path":90,"practice":4640,"rawbody":4657,"readingTime":4658,"seo":4663,"sources":4664,"status":4671,"stem":4672,"summary":92,"topics":4673,"__hash__":4674},"course\u002F01.algorithms\u002F04.data-structures\u002F03.binary-search-trees.md","",{"type":378,"value":379,"toc":4624},"minimark",[380,444,449,470,694,711,812,1020,1023,1075,1120,1252,1612,1669,1717,1721,1760,1848,1880,1884,1935,2026,2071,2126,2460,2464,2467,2680,2740,2789,2863,2898,3122,3195,3199,3213,3243,3274,3542,3587,3591,3732,3799,3902,3991,3994,4107,4249,4253,4484,4620],[381,382,383,384,388,389,429,430,434,435,439,440,443],"p",{},"A ",[385,386,387],"a",{"href":84},"hash table"," gives expected ",[390,391,394],"span",{"className":392},[393],"katex",[390,395,399],{"className":396,"ariaHidden":398},[397],"katex-html","true",[390,400,403,408,415,420,424],{"className":401},[402],"base",[390,404],{"className":405,"style":407},[406],"strut","height:1em;vertical-align:-0.25em;",[390,409,414],{"className":410,"style":413},[411,412],"mord","mathnormal","margin-right:0.0278em;","O",[390,416,419],{"className":417},[418],"mopen","(",[390,421,423],{"className":422},[411],"1",[390,425,428],{"className":426},[427],"mclose",")"," lookups but throws away order: it cannot tell\nyou the smallest key, the next key after a given one, or every key in a range. A\n",[431,432,433],"strong",{},"binary search tree"," (BST) keeps those queries fast by storing keys in a\nshape that ",[436,437,438],"em",{},"records"," their order. Each node holds a key and pointers to a left\nchild, a right child, and a parent; the keys are arranged so that the tree itself\nis a kind of decision diagram for searching. The result is a dynamic ordered\ndictionary supporting search, insert, delete, minimum, maximum, predecessor,\nsuccessor, and in-order traversal, every one of them in time proportional to\nthe tree's ",[431,441,442],{},"height",".",[445,446,448],"h2",{"id":447},"the-binary-search-tree-property","The binary search tree property",[381,450,451,452,469],{},"The arrangement is governed by one local invariant, checked at every node ",[390,453,455],{"className":454},[393],[390,456,458],{"className":457,"ariaHidden":398},[397],[390,459,461,465],{"className":460},[402],[390,462],{"className":463,"style":464},[406],"height:0.4306em;",[390,466,468],{"className":467},[411,412],"x",":",[471,472,474],"callout",{"type":473},"lemma",[381,475,476,479,480,495,496,514,515,518,519,534,535,599,600,615,616,619,620,635,636,443],{},[431,477,478],{},"Property (BST)."," For every node ",[390,481,483],{"className":482},[393],[390,484,486],{"className":485,"ariaHidden":398},[397],[390,487,489,492],{"className":488},[402],[390,490],{"className":491,"style":464},[406],[390,493,468],{"className":494},[411,412],": if ",[390,497,499],{"className":498},[393],[390,500,502],{"className":501,"ariaHidden":398},[397],[390,503,505,509],{"className":504},[402],[390,506],{"className":507,"style":508},[406],"height:0.625em;vertical-align:-0.1944em;",[390,510,513],{"className":511,"style":512},[411,412],"margin-right:0.0359em;","y"," is a node in the ",[436,516,517],{},"left"," subtree of\n",[390,520,522],{"className":521},[393],[390,523,525],{"className":524,"ariaHidden":398},[397],[390,526,528,531],{"className":527},[402],[390,529],{"className":530,"style":464},[406],[390,532,468],{"className":533},[411,412],", then ",[390,536,538],{"className":537},[393],[390,539,541,578],{"className":540,"ariaHidden":398},[397],[390,542,544,547,552,556,559,562,565,570,575],{"className":543},[402],[390,545],{"className":546,"style":407},[406],[390,548,551],{"className":549,"style":550},[411,412],"margin-right:0.0315em;","k",[390,553,555],{"className":554,"style":512},[411,412],"ey",[390,557,419],{"className":558},[418],[390,560,513],{"className":561,"style":512},[411,412],[390,563,428],{"className":564},[427],[390,566],{"className":567,"style":569},[568],"mspace","margin-right:0.2778em;",[390,571,574],{"className":572},[573],"mrel","≤",[390,576],{"className":577,"style":569},[568],[390,579,581,584,587,590,593,596],{"className":580},[402],[390,582],{"className":583,"style":407},[406],[390,585,551],{"className":586,"style":550},[411,412],[390,588,555],{"className":589,"style":512},[411,412],[390,591,419],{"className":592},[418],[390,594,468],{"className":595},[411,412],[390,597,428],{"className":598},[427],"; and if ",[390,601,603],{"className":602},[393],[390,604,606],{"className":605,"ariaHidden":398},[397],[390,607,609,612],{"className":608},[402],[390,610],{"className":611,"style":508},[406],[390,613,513],{"className":614,"style":512},[411,412]," is in the ",[436,617,618],{},"right"," subtree of ",[390,621,623],{"className":622},[393],[390,624,626],{"className":625,"ariaHidden":398},[397],[390,627,629,632],{"className":628},[402],[390,630],{"className":631,"style":464},[406],[390,633,468],{"className":634},[411,412],",\nthen ",[390,637,639],{"className":638},[393],[390,640,642,673],{"className":641,"ariaHidden":398},[397],[390,643,645,648,651,654,657,660,663,666,670],{"className":644},[402],[390,646],{"className":647,"style":407},[406],[390,649,551],{"className":650,"style":550},[411,412],[390,652,555],{"className":653,"style":512},[411,412],[390,655,419],{"className":656},[418],[390,658,513],{"className":659,"style":512},[411,412],[390,661,428],{"className":662},[427],[390,664],{"className":665,"style":569},[568],[390,667,669],{"className":668},[573],"≥",[390,671],{"className":672,"style":569},[568],[390,674,676,679,682,685,688,691],{"className":675},[402],[390,677],{"className":678,"style":407},[406],[390,680,551],{"className":681,"style":550},[411,412],[390,683,555],{"className":684,"style":512},[411,412],[390,686,419],{"className":687},[418],[390,689,468],{"className":690},[411,412],[390,692,428],{"className":693},[427],[381,695,696,697,700,701,710],{},"Smaller keys live to the left, larger keys to the right, ",[436,698,699],{},"everywhere",", not just\nbetween a node and its immediate children.",[702,703,704],"sup",{},[385,705,423],{"href":706,"ariaDescribedBy":707,"dataFootnoteRef":376,"id":709},"#user-content-fn-clrs-bst",[708],"footnote-label","user-content-fnref-clrs-bst"," This recursive constraint is exactly\nwhat lets a search discard half the tree at each step.",[712,713,717,806],"figure",{"className":714},[715,716],"tikz-figure","tikz-diagram-rendered",[718,719,724],"svg",{"xmlns":720,"width":721,"height":722,"viewBox":723},"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","206.456","129.932","-75 -75 154.842 97.449",[725,726,729,734,743,746,753,756,763,766,773,776,783,786,793,796,803],"g",{"stroke":727,"style":728},"currentColor","stroke-miterlimit:10;stroke-width:.4",[730,731],"path",{"fill":732,"d":733},"none","M15.199-60.689c0-6.286-5.096-11.381-11.381-11.381S-7.563-66.975-7.563-60.689s5.095 11.381 11.38 11.381S15.2-54.403 15.2-60.688Zm-11.381 0",[725,735,737],{"transform":736},"translate(-2.5 3.222)",[730,738],{"d":739,"fill":727,"stroke":727,"className":740,"style":742},"M6.318-60.469Q5.698-60.469 5.283-60.799Q4.868-61.128 4.641-61.653Q4.414-62.178 4.326-62.754Q4.238-63.331 4.238-63.921Q4.238-64.712 4.546-65.508Q4.853-66.304 5.451-66.827Q6.049-67.349 6.870-67.349Q7.212-67.349 7.507-67.220Q7.802-67.090 7.971-66.839Q8.139-66.587 8.139-66.231Q8.139-66.026 8-65.887Q7.861-65.748 7.656-65.748Q7.461-65.748 7.319-65.889Q7.177-66.031 7.177-66.231Q7.177-66.426 7.319-66.568Q7.461-66.710 7.656-66.710L7.710-66.710Q7.583-66.890 7.351-66.976Q7.119-67.061 6.870-67.061Q6.567-67.061 6.311-66.929Q6.054-66.797 5.849-66.573Q5.644-66.348 5.507-66.077Q5.371-65.806 5.295-65.460Q5.219-65.113 5.200-64.810Q5.180-64.507 5.180-64.048Q5.356-64.459 5.678-64.720Q6.001-64.981 6.406-64.981Q6.850-64.981 7.216-64.800Q7.583-64.620 7.846-64.300Q8.110-63.980 8.249-63.570Q8.388-63.160 8.388-62.740Q8.388-62.154 8.127-61.624Q7.866-61.094 7.392-60.782Q6.919-60.469 6.318-60.469M6.318-60.787Q6.704-60.787 6.938-60.962Q7.172-61.138 7.282-61.429Q7.392-61.719 7.419-62.015Q7.446-62.310 7.446-62.740Q7.446-63.306 7.392-63.707Q7.339-64.107 7.099-64.412Q6.860-64.717 6.367-64.717Q5.962-64.717 5.700-64.444Q5.439-64.170 5.319-63.753Q5.200-63.335 5.200-62.950Q5.200-62.818 5.210-62.750Q5.210-62.735 5.207-62.725Q5.205-62.715 5.200-62.701Q5.200-62.271 5.288-61.832Q5.376-61.392 5.625-61.089Q5.874-60.787 6.318-60.787",[741],"tikz-text","stroke-width:0.300",[730,744],{"fill":732,"d":745},"M-24.635-26.546c0-6.285-5.095-11.38-11.381-11.38s-11.381 5.095-11.381 11.38 5.095 11.381 11.38 11.381c6.287 0 11.382-5.095 11.382-11.38Zm-11.381 0",[725,747,749],{"transform":748},"translate(-42.334 37.366)",[730,750],{"d":751,"fill":727,"stroke":727,"className":752,"style":742},"M4.819-61.460L4.770-61.460Q5.005-61.119 5.400-60.953Q5.796-60.787 6.250-60.787Q6.831-60.787 7.075-61.282Q7.319-61.778 7.319-62.408Q7.319-62.691 7.268-62.974Q7.216-63.257 7.094-63.502Q6.972-63.746 6.760-63.892Q6.547-64.039 6.240-64.039L5.576-64.039Q5.488-64.039 5.488-64.131L5.488-64.219Q5.488-64.297 5.576-64.297L6.128-64.341Q6.479-64.341 6.711-64.605Q6.943-64.869 7.050-65.247Q7.158-65.626 7.158-65.967Q7.158-66.446 6.933-66.753Q6.709-67.061 6.250-67.061Q5.869-67.061 5.522-66.917Q5.175-66.773 4.970-66.480Q4.990-66.485 5.005-66.487Q5.019-66.490 5.039-66.490Q5.263-66.490 5.415-66.334Q5.566-66.177 5.566-65.958Q5.566-65.743 5.415-65.586Q5.263-65.430 5.039-65.430Q4.819-65.430 4.663-65.586Q4.506-65.743 4.506-65.958Q4.506-66.387 4.765-66.705Q5.024-67.022 5.432-67.186Q5.839-67.349 6.250-67.349Q6.552-67.349 6.889-67.259Q7.226-67.168 7.500-67Q7.773-66.832 7.946-66.568Q8.120-66.304 8.120-65.967Q8.120-65.547 7.932-65.191Q7.744-64.835 7.417-64.576Q7.089-64.317 6.699-64.190Q7.133-64.107 7.524-63.863Q7.915-63.619 8.151-63.238Q8.388-62.857 8.388-62.418Q8.388-61.866 8.086-61.419Q7.783-60.972 7.290-60.721Q6.797-60.469 6.250-60.469Q5.781-60.469 5.310-60.647Q4.839-60.826 4.538-61.182Q4.238-61.539 4.238-62.037Q4.238-62.286 4.404-62.452Q4.570-62.618 4.819-62.618Q4.980-62.618 5.114-62.542Q5.249-62.466 5.324-62.330Q5.400-62.193 5.400-62.037Q5.400-61.793 5.229-61.627Q5.058-61.460 4.819-61.460",[741],[730,754],{"fill":732,"d":755},"m-4.975-53.152-22.249 19.07M-45.975 7.598c0-6.286-5.095-11.381-11.38-11.381s-11.382 5.095-11.382 11.38S-63.64 18.98-57.356 18.98s11.381-5.096 11.381-11.381Zm-11.38 0",[725,757,759],{"transform":758},"translate(-63.673 71.509)",[730,760],{"d":761,"fill":727,"stroke":727,"className":762,"style":742},"M8.027-60.689L4.316-60.689L4.316-60.958Q4.316-60.982 4.336-61.011L5.888-62.730Q6.240-63.111 6.460-63.370Q6.679-63.628 6.894-63.965Q7.109-64.302 7.234-64.651Q7.358-65.001 7.358-65.391Q7.358-65.801 7.207-66.175Q7.055-66.548 6.755-66.773Q6.455-66.998 6.030-66.998Q5.595-66.998 5.249-66.736Q4.902-66.475 4.760-66.060Q4.799-66.070 4.868-66.070Q5.092-66.070 5.251-65.918Q5.410-65.767 5.410-65.528Q5.410-65.298 5.251-65.140Q5.092-64.981 4.868-64.981Q4.633-64.981 4.475-65.145Q4.316-65.308 4.316-65.528Q4.316-65.904 4.458-66.233Q4.599-66.563 4.865-66.819Q5.131-67.076 5.466-67.212Q5.800-67.349 6.176-67.349Q6.748-67.349 7.241-67.107Q7.734-66.866 8.022-66.424Q8.310-65.982 8.310-65.391Q8.310-64.957 8.120-64.566Q7.929-64.175 7.631-63.856Q7.334-63.536 6.870-63.130Q6.406-62.725 6.259-62.588L5.127-61.500L6.089-61.500Q6.797-61.500 7.273-61.512Q7.749-61.524 7.778-61.548Q7.895-61.675 8.017-62.471L8.310-62.471",[741],[730,764],{"fill":732,"d":765},"m-42.154-16.725-9.064 14.502M-3.295 7.598c0-6.286-5.096-11.381-11.381-11.381s-11.382 5.095-11.382 11.38 5.096 11.382 11.382 11.382 11.38-5.096 11.38-11.381Zm-11.381 0",[725,767,769],{"transform":768},"translate(-20.994 71.509)",[730,770],{"d":771,"fill":727,"stroke":727,"className":772,"style":742},"M4.687-61.827Q4.790-61.534 5.002-61.294Q5.214-61.055 5.505-60.921Q5.796-60.787 6.108-60.787Q6.831-60.787 7.104-61.348Q7.378-61.910 7.378-62.710Q7.378-63.057 7.365-63.294Q7.353-63.531 7.299-63.751Q7.207-64.102 6.975-64.366Q6.743-64.629 6.406-64.629Q6.069-64.629 5.827-64.527Q5.586-64.424 5.434-64.288Q5.283-64.151 5.166-64Q5.048-63.848 5.019-63.838L4.907-63.838Q4.882-63.838 4.846-63.870Q4.809-63.902 4.809-63.931L4.809-67.271Q4.809-67.295 4.841-67.322Q4.873-67.349 4.907-67.349L4.936-67.349Q5.610-67.027 6.367-67.027Q7.109-67.027 7.797-67.349L7.827-67.349Q7.861-67.349 7.890-67.325Q7.920-67.300 7.920-67.271L7.920-67.178Q7.920-67.129 7.900-67.129Q7.558-66.675 7.043-66.421Q6.528-66.168 5.976-66.168Q5.576-66.168 5.156-66.280L5.156-64.390Q5.488-64.659 5.749-64.773Q6.010-64.888 6.416-64.888Q6.967-64.888 7.404-64.571Q7.841-64.253 8.076-63.743Q8.310-63.233 8.310-62.701Q8.310-62.100 8.015-61.587Q7.719-61.075 7.212-60.772Q6.704-60.469 6.108-60.469Q5.615-60.469 5.202-60.723Q4.790-60.977 4.553-61.407Q4.316-61.836 4.316-62.320Q4.316-62.544 4.463-62.686Q4.609-62.828 4.829-62.828Q5.048-62.828 5.197-62.684Q5.346-62.540 5.346-62.320Q5.346-62.105 5.197-61.956Q5.048-61.807 4.829-61.807Q4.795-61.807 4.751-61.814Q4.707-61.822 4.687-61.827",[741],[730,774],{"fill":732,"d":775},"m-29.878-16.725 9.064 14.502M55.033-26.546c0-6.285-5.096-11.38-11.381-11.38S32.27-32.832 32.27-26.547s5.095 11.381 11.38 11.381 11.382-5.095 11.382-11.38Zm-11.381 0",[725,777,779],{"transform":778},"translate(37.334 37.366)",[730,780],{"d":781,"fill":727,"stroke":727,"className":782,"style":742},"M4.238-62.208Q4.238-62.808 4.633-63.270Q5.029-63.731 5.649-64.039L5.278-64.278Q4.936-64.502 4.721-64.876Q4.506-65.250 4.506-65.660Q4.506-66.138 4.758-66.524Q5.009-66.910 5.427-67.129Q5.844-67.349 6.318-67.349Q6.762-67.349 7.175-67.168Q7.588-66.988 7.854-66.651Q8.120-66.314 8.120-65.850Q8.120-65.513 7.961-65.225Q7.802-64.937 7.526-64.708Q7.251-64.478 6.938-64.317L7.509-63.951Q7.905-63.692 8.147-63.272Q8.388-62.852 8.388-62.388Q8.388-61.846 8.098-61.402Q7.807-60.958 7.329-60.713Q6.850-60.469 6.318-60.469Q5.800-60.469 5.319-60.679Q4.839-60.889 4.538-61.287Q4.238-61.685 4.238-62.208M4.780-62.208Q4.780-61.812 4.997-61.485Q5.214-61.158 5.571-60.972Q5.927-60.787 6.318-60.787Q6.899-60.787 7.373-61.126Q7.846-61.465 7.846-62.027Q7.846-62.217 7.771-62.405Q7.695-62.593 7.561-62.747Q7.426-62.901 7.260-62.999L5.918-63.868Q5.605-63.702 5.344-63.448Q5.083-63.194 4.931-62.877Q4.780-62.559 4.780-62.208M5.468-65.259L6.679-64.478Q7.099-64.722 7.368-65.069Q7.636-65.416 7.636-65.850Q7.636-66.187 7.448-66.468Q7.260-66.749 6.958-66.905Q6.655-67.061 6.308-67.061Q6.005-67.061 5.698-66.944Q5.390-66.827 5.190-66.595Q4.990-66.363 4.990-66.050Q4.990-65.582 5.468-65.259",[741],[730,784],{"fill":732,"d":785},"m12.61-53.152 22.25 19.07M33.693 7.598c0-6.286-5.095-11.381-11.38-11.381-6.287 0-11.382 5.095-11.382 11.38S16.026 18.98 22.312 18.98s11.381-5.096 11.381-11.381Zm-11.38 0",[725,787,789],{"transform":788},"translate(15.994 71.509)",[730,790],{"d":791,"fill":727,"stroke":727,"className":792,"style":742},"M5.556-60.948Q5.556-61.504 5.654-62.037Q5.752-62.569 5.940-63.089Q6.128-63.609 6.394-64.109Q6.660-64.610 6.977-65.049L7.890-66.319L6.748-66.319Q4.970-66.319 4.917-66.270Q4.785-66.109 4.668-65.347L4.380-65.347L4.707-67.447L5-67.447L5-67.418Q5-67.237 5.610-67.183Q6.220-67.129 6.806-67.129L8.667-67.129L8.667-66.871Q8.667-66.861 8.664-66.856Q8.662-66.851 8.657-66.841L7.280-64.908Q6.772-64.156 6.645-63.238Q6.518-62.320 6.518-60.948Q6.518-60.752 6.377-60.611Q6.235-60.469 6.040-60.469Q5.839-60.469 5.698-60.611Q5.556-60.752 5.556-60.948",[741],[730,794],{"fill":732,"d":795},"M37.514-16.725 28.45-2.223M76.372 7.598c0-6.286-5.095-11.381-11.38-11.381S53.61 1.312 53.61 7.597 58.706 18.98 64.991 18.98s11.381-5.096 11.381-11.381Zm-11.38 0",[725,797,799],{"transform":798},"translate(58.673 71.509)",[730,800],{"d":801,"fill":727,"stroke":727,"className":802,"style":742},"M4.970-61.109L4.946-61.109Q5.219-60.787 5.898-60.787Q6.279-60.787 6.609-61.045Q6.938-61.304 7.119-61.680Q7.329-62.105 7.387-62.586Q7.446-63.067 7.446-63.780Q7.275-63.375 6.955-63.116Q6.635-62.857 6.220-62.857Q5.639-62.857 5.183-63.172Q4.726-63.487 4.482-64.002Q4.238-64.517 4.238-65.098Q4.238-65.699 4.511-66.219Q4.785-66.739 5.268-67.044Q5.752-67.349 6.367-67.349Q6.972-67.349 7.380-67.020Q7.788-66.690 8.003-66.170Q8.217-65.650 8.303-65.069Q8.388-64.488 8.388-63.921Q8.388-63.150 8.105-62.347Q7.822-61.543 7.258-61.006Q6.694-60.469 5.898-60.469Q5.307-60.469 4.897-60.748Q4.487-61.026 4.487-61.587Q4.487-61.793 4.626-61.932Q4.765-62.071 4.970-62.071Q5.171-62.071 5.310-61.932Q5.449-61.793 5.449-61.587Q5.449-61.392 5.307-61.251Q5.166-61.109 4.970-61.109M6.259-63.121Q6.670-63.121 6.931-63.397Q7.192-63.672 7.309-64.083Q7.426-64.493 7.426-64.898L7.426-65.088L7.426-65.127Q7.426-65.879 7.207-66.470Q6.987-67.061 6.367-67.061Q5.971-67.061 5.725-66.888Q5.478-66.714 5.361-66.426Q5.244-66.138 5.212-65.811Q5.180-65.484 5.180-65.098Q5.180-64.532 5.234-64.131Q5.288-63.731 5.527-63.426Q5.766-63.121 6.259-63.121",[741],[730,804],{"fill":732,"d":805},"m49.79-16.725 9.063 14.502",[807,808,811],"figcaption",{"className":809},[810],"tikz-cap","A binary search tree with smaller keys left and larger keys right",[381,813,814,815,832,833,886,887,915,916,886,961,988,989,1004,1005,443],{},"Reading this tree: the root is ",[390,816,818],{"className":817},[393],[390,819,821],{"className":820,"ariaHidden":398},[397],[390,822,824,828],{"className":823},[402],[390,825],{"className":826,"style":827},[406],"height:0.6444em;",[390,829,831],{"className":830},[411],"6","; everything in its left subtree\n(",[390,834,836],{"className":835},[393],[390,837,839],{"className":838,"ariaHidden":398},[397],[390,840,842,845],{"className":841},[402],[390,843],{"className":844,"style":407},[406],[390,846,849,855,859,864,868,872,875,878,882],{"className":847},[848],"minner",[390,850,854],{"className":851,"style":853},[418,852],"delimcenter","top:0em;","{",[390,856,858],{"className":857},[411],"2",[390,860,863],{"className":861},[862],"mpunct",",",[390,865],{"className":866,"style":867},[568],"margin-right:0.1667em;",[390,869,871],{"className":870},[411],"3",[390,873,863],{"className":874},[862],[390,876],{"className":877,"style":867},[568],[390,879,881],{"className":880},[411],"5",[390,883,885],{"className":884,"style":853},[427,852],"}",") is ",[390,888,890],{"className":889},[393],[390,891,893,906],{"className":892,"ariaHidden":398},[397],[390,894,896,900,903],{"className":895},[402],[390,897],{"className":898,"style":899},[406],"height:0.7719em;vertical-align:-0.136em;",[390,901,574],{"className":902},[573],[390,904],{"className":905,"style":569},[568],[390,907,909,912],{"className":908},[402],[390,910],{"className":911,"style":827},[406],[390,913,831],{"className":914},[411]," and everything in its right subtree\n(",[390,917,919],{"className":918},[393],[390,920,922],{"className":921,"ariaHidden":398},[397],[390,923,925,928],{"className":924},[402],[390,926],{"className":927,"style":407},[406],[390,929,931,934,938,941,944,948,951,954,958],{"className":930},[848],[390,932,854],{"className":933,"style":853},[418,852],[390,935,937],{"className":936},[411],"7",[390,939,863],{"className":940},[862],[390,942],{"className":943,"style":867},[568],[390,945,947],{"className":946},[411],"8",[390,949,863],{"className":950},[862],[390,952],{"className":953,"style":867},[568],[390,955,957],{"className":956},[411],"9",[390,959,885],{"className":960,"style":853},[427,852],[390,962,964],{"className":963},[393],[390,965,967,979],{"className":966,"ariaHidden":398},[397],[390,968,970,973,976],{"className":969},[402],[390,971],{"className":972,"style":899},[406],[390,974,669],{"className":975},[573],[390,977],{"className":978,"style":569},[568],[390,980,982,985],{"className":981},[402],[390,983],{"className":984,"style":827},[406],[390,986,831],{"className":987},[411],", and the same holds recursively at ",[390,990,992],{"className":991},[393],[390,993,995],{"className":994,"ariaHidden":398},[397],[390,996,998,1001],{"className":997},[402],[390,999],{"className":1000,"style":827},[406],[390,1002,871],{"className":1003},[411]," and ",[390,1006,1008],{"className":1007},[393],[390,1009,1011],{"className":1010,"ariaHidden":398},[397],[390,1012,1014,1017],{"className":1013},[402],[390,1015],{"className":1016,"style":827},[406],[390,1018,947],{"className":1019},[411],[445,1021,139],{"id":1022},"searching",[381,1024,1025,1026,1042,1043,1058,1059,1074],{},"To search for a key ",[390,1027,1029],{"className":1028},[393],[390,1030,1032],{"className":1031,"ariaHidden":398},[397],[390,1033,1035,1039],{"className":1034},[402],[390,1036],{"className":1037,"style":1038},[406],"height:0.6944em;",[390,1040,551],{"className":1041,"style":550},[411,412],", start at the root and walk down. At each node, if ",[390,1044,1046],{"className":1045},[393],[390,1047,1049],{"className":1048,"ariaHidden":398},[397],[390,1050,1052,1055],{"className":1051},[402],[390,1053],{"className":1054,"style":1038},[406],[390,1056,551],{"className":1057,"style":550},[411,412],"\nequals the node's key we are done; if ",[390,1060,1062],{"className":1061},[393],[390,1063,1065],{"className":1064,"ariaHidden":398},[397],[390,1066,1068,1071],{"className":1067},[402],[390,1069],{"className":1070,"style":1038},[406],[390,1072,551],{"className":1073,"style":550},[411,412]," is smaller we go left, otherwise we go\nright. Each comparison drops us one level, so the search traces a single\nroot-to-leaf path.",[1076,1077,1081],"pre",{"className":1078,"code":1079,"language":1080,"meta":376,"style":376},"language-algorithm shiki shiki-themes Vesper Light - Orange Boost (Quick Open Adjusted) vesper","caption: $\\textsc{Tree-Search}(x, k)$ — find key $k$ in the subtree rooted at $x$\nif $x = \\text{nil}$ or $k = key(x)$ then\n  return $x$\nif $k \u003C key(x)$ then\n  return call $\\textsc{Tree-Search}(left(x), k)$ \u002F\u002F k is in the left subtree\nelse\n  return call $\\textsc{Tree-Search}(right(x), k)$ \u002F\u002F k is in the right subtree\n","algorithm",[1082,1083,1084,1090,1095,1100,1105,1110,1115],"code",{"__ignoreMap":376},[390,1085,1087],{"class":1086,"line":6},"line",[390,1088,1089],{},"caption: $\\textsc{Tree-Search}(x, k)$ — find key $k$ in the subtree rooted at $x$\n",[390,1091,1092],{"class":1086,"line":18},[390,1093,1094],{},"if $x = \\text{nil}$ or $k = key(x)$ then\n",[390,1096,1097],{"class":1086,"line":24},[390,1098,1099],{},"  return $x$\n",[390,1101,1102],{"class":1086,"line":73},[390,1103,1104],{},"if $k \u003C key(x)$ then\n",[390,1106,1107],{"class":1086,"line":102},[390,1108,1109],{},"  return call $\\textsc{Tree-Search}(left(x), k)$ \u002F\u002F k is in the left subtree\n",[390,1111,1112],{"class":1086,"line":108},[390,1113,1114],{},"else\n",[390,1116,1117],{"class":1086,"line":116},[390,1118,1119],{},"  return call $\\textsc{Tree-Search}(right(x), k)$ \u002F\u002F k is in the right subtree\n",[381,1121,1122,1123,1170,1171,1186,1187,1202,1203,1228,1229,1244,1245],{},"The procedure is correct by the BST property: when ",[390,1124,1126],{"className":1125},[393],[390,1127,1129,1149],{"className":1128,"ariaHidden":398},[397],[390,1130,1132,1136,1139,1142,1146],{"className":1131},[402],[390,1133],{"className":1134,"style":1135},[406],"height:0.7335em;vertical-align:-0.0391em;",[390,1137,551],{"className":1138,"style":550},[411,412],[390,1140],{"className":1141,"style":569},[568],[390,1143,1145],{"className":1144},[573],"\u003C",[390,1147],{"className":1148,"style":569},[568],[390,1150,1152,1155,1158,1161,1164,1167],{"className":1151},[402],[390,1153],{"className":1154,"style":407},[406],[390,1156,551],{"className":1157,"style":550},[411,412],[390,1159,555],{"className":1160,"style":512},[411,412],[390,1162,419],{"className":1163},[418],[390,1165,468],{"className":1166},[411,412],[390,1168,428],{"className":1169},[427],", the property\nguarantees ",[390,1172,1174],{"className":1173},[393],[390,1175,1177],{"className":1176,"ariaHidden":398},[397],[390,1178,1180,1183],{"className":1179},[402],[390,1181],{"className":1182,"style":1038},[406],[390,1184,551],{"className":1185,"style":550},[411,412]," cannot be in ",[390,1188,1190],{"className":1189},[393],[390,1191,1193],{"className":1192,"ariaHidden":398},[397],[390,1194,1196,1199],{"className":1195},[402],[390,1197],{"className":1198,"style":464},[406],[390,1200,468],{"className":1201},[411,412],"'s right subtree, so discarding it loses nothing.\nThe search visits one node per level and runs in ",[390,1204,1206],{"className":1205},[393],[390,1207,1209],{"className":1208,"ariaHidden":398},[397],[390,1210,1212,1215,1218,1221,1225],{"className":1211},[402],[390,1213],{"className":1214,"style":407},[406],[390,1216,414],{"className":1217,"style":413},[411,412],[390,1219,419],{"className":1220},[418],[390,1222,1224],{"className":1223},[411,412],"h",[390,1226,428],{"className":1227},[427]," time, where ",[390,1230,1232],{"className":1231},[393],[390,1233,1235],{"className":1234,"ariaHidden":398},[397],[390,1236,1238,1241],{"className":1237},[402],[390,1239],{"className":1240,"style":1038},[406],[390,1242,1224],{"className":1243},[411,412]," is the\nheight of the tree.",[702,1246,1247],{},[385,1248,858],{"href":1249,"ariaDescribedBy":1250,"dataFootnoteRef":376,"id":1251},"#user-content-fn-skiena-bst",[708],"user-content-fnref-skiena-bst",[712,1253,1255,1424],{"className":1254},[715,716],[718,1256,1260],{"xmlns":720,"width":1257,"height":1258,"viewBox":1259},"273.807","130.998","-75 -75 205.355 98.249",[725,1261,1262,1265,1273,1276,1283,1286,1293,1296,1303,1306,1313,1316,1323,1326,1333,1336,1343,1385,1393,1398,1402,1407,1416],{"stroke":727,"style":728},[730,1263],{"fill":732,"d":1264},"M14.264-60.289c0-6.286-5.095-11.381-11.38-11.381S-8.499-66.575-8.499-60.289s5.096 11.381 11.381 11.381 11.381-5.095 11.381-11.38Zm-11.38 0",[725,1266,1268],{"transform":1267},"translate(-2.312 2.9)",[730,1269],{"d":1270,"fill":727,"stroke":727,"className":1271,"style":1272},"M5.195-60.091Q4.461-60.091 4.030-60.572Q3.599-61.054 3.435-61.746Q3.270-62.438 3.270-63.185Q3.270-63.914 3.562-64.637Q3.854-65.360 4.408-65.822Q4.962-66.283 5.709-66.283Q6.205-66.283 6.541-66.017Q6.878-65.751 6.878-65.268Q6.878-65.088 6.750-64.960Q6.623-64.833 6.447-64.833Q6.267-64.833 6.137-64.958Q6.008-65.083 6.008-65.268Q6.008-65.382 6.065-65.486Q6.122-65.589 6.223-65.648Q6.324-65.707 6.447-65.707Q6.451-65.707 6.456-65.705Q6.460-65.703 6.465-65.699Q6.350-65.866 6.142-65.945Q5.933-66.024 5.709-66.024Q5.265-66.024 4.907-65.723Q4.549-65.422 4.360-64.969Q4.127-64.363 4.127-63.330Q4.298-63.695 4.599-63.923Q4.900-64.152 5.287-64.152Q5.691-64.152 6.036-63.985Q6.381-63.818 6.618-63.537Q6.856-63.255 6.985-62.893Q7.115-62.530 7.115-62.126Q7.115-61.581 6.871-61.115Q6.627-60.649 6.188-60.370Q5.748-60.091 5.195-60.091M5.195-60.377Q5.656-60.377 5.891-60.634Q6.126-60.891 6.192-61.265Q6.258-61.638 6.258-62.108L6.258-62.143Q6.258-62.631 6.201-62.996Q6.144-63.361 5.915-63.624Q5.687-63.888 5.243-63.888Q4.874-63.888 4.623-63.644Q4.373-63.400 4.258-63.036Q4.144-62.671 4.144-62.324Q4.144-62.205 4.153-62.143Q4.153-62.126 4.151-62.115Q4.149-62.104 4.144-62.091Q4.144-61.440 4.382-60.909Q4.619-60.377 5.195-60.377",[741],"stroke-width:0.270",[730,1274],{"fill":732,"d":1275},"M-22.724-26.146c0-6.285-5.096-11.38-11.381-11.38s-11.381 5.095-11.381 11.38 5.095 11.381 11.38 11.381 11.382-5.095 11.382-11.38Zm-11.381 0",[725,1277,1279],{"transform":1278},"translate(-39.301 37.043)",[730,1280],{"d":1281,"fill":727,"stroke":727,"className":1282,"style":1272},"M3.784-61.010L3.740-61.010Q3.942-60.693 4.329-60.535Q4.716-60.377 5.142-60.377Q5.678-60.377 5.917-60.812Q6.157-61.247 6.157-61.827Q6.157-62.407 5.911-62.847Q5.665-63.286 5.133-63.286L4.513-63.286Q4.487-63.286 4.454-63.315Q4.421-63.343 4.421-63.365L4.421-63.466Q4.421-63.497 4.450-63.521Q4.478-63.545 4.513-63.545L5.032-63.585Q5.498-63.585 5.744-64.057Q5.990-64.530 5.990-65.048Q5.990-65.475 5.777-65.749Q5.564-66.024 5.142-66.024Q4.799-66.024 4.474-65.894Q4.149-65.765 3.964-65.510L3.990-65.510Q4.193-65.510 4.329-65.369Q4.465-65.228 4.465-65.031Q4.465-64.833 4.331-64.699Q4.197-64.565 3.999-64.565Q3.797-64.565 3.659-64.699Q3.520-64.833 3.520-65.031Q3.520-65.620 4.023-65.951Q4.527-66.283 5.142-66.283Q5.520-66.283 5.922-66.143Q6.324-66.002 6.592-65.723Q6.860-65.444 6.860-65.048Q6.860-64.499 6.506-64.062Q6.153-63.624 5.612-63.440Q6.003-63.361 6.348-63.137Q6.693-62.913 6.904-62.572Q7.115-62.231 7.115-61.836Q7.115-61.454 6.952-61.131Q6.790-60.808 6.498-60.572Q6.205-60.337 5.858-60.214Q5.511-60.091 5.142-60.091Q4.694-60.091 4.263-60.252Q3.832-60.412 3.551-60.739Q3.270-61.067 3.270-61.524Q3.270-61.739 3.417-61.882Q3.564-62.025 3.784-62.025Q3.995-62.025 4.140-61.880Q4.285-61.735 4.285-61.524Q4.285-61.313 4.138-61.161Q3.990-61.010 3.784-61.010",[741],[730,1284],{"fill":732,"d":1285},"m-5.626-52.434-19.97 18.433M-42.641 7.998c0-6.286-5.096-11.381-11.381-11.381s-11.381 5.095-11.381 11.38 5.095 11.382 11.38 11.382S-42.64 14.283-42.64 7.998Zm-11.381 0",[725,1287,1289],{"transform":1288},"translate(-59.218 71.187)",[730,1290],{"d":1291,"fill":727,"stroke":727,"className":1292,"style":1272},"M6.790-60.289L3.340-60.289L3.340-60.522Q3.340-60.535 3.371-60.566L4.825-62.143Q5.291-62.640 5.544-62.945Q5.797-63.251 5.988-63.662Q6.179-64.073 6.179-64.512Q6.179-65.101 5.856-65.534Q5.533-65.967 4.953-65.967Q4.689-65.967 4.443-65.857Q4.197-65.747 4.021-65.560Q3.845-65.373 3.749-65.123L3.828-65.123Q4.030-65.123 4.173-64.987Q4.316-64.851 4.316-64.635Q4.316-64.429 4.173-64.290Q4.030-64.152 3.828-64.152Q3.626-64.152 3.483-64.295Q3.340-64.437 3.340-64.635Q3.340-65.097 3.577-65.470Q3.815-65.844 4.215-66.063Q4.614-66.283 5.063-66.283Q5.586-66.283 6.040-66.068Q6.495-65.852 6.768-65.453Q7.040-65.053 7.040-64.512Q7.040-64.117 6.869-63.763Q6.697-63.409 6.432-63.130Q6.166-62.851 5.715-62.466Q5.265-62.082 5.186-62.007L4.162-61.045L4.979-61.045Q5.630-61.045 6.067-61.056Q6.504-61.067 6.535-61.089Q6.605-61.172 6.660-61.412Q6.715-61.651 6.755-61.919L7.040-61.919",[741],[730,1294],{"fill":732,"d":1295},"m-39.94-16.143-8.247 14.138M-2.807 7.998c0-6.286-5.096-11.381-11.381-11.381S-25.57 1.712-25.57 7.997s5.096 11.382 11.382 11.382 11.38-5.096 11.38-11.381Zm-11.381 0",[725,1297,1299],{"transform":1298},"translate(-19.384 71.187)",[730,1300],{"d":1301,"fill":727,"stroke":727,"className":1302,"style":1272},"M3.709-61.295Q3.850-60.882 4.210-60.630Q4.571-60.377 5.006-60.377Q5.458-60.377 5.724-60.630Q5.990-60.882 6.093-61.267Q6.196-61.651 6.196-62.108Q6.196-63.809 5.287-63.809Q4.966-63.809 4.737-63.715Q4.509-63.620 4.379-63.501Q4.250-63.383 4.138-63.244Q4.026-63.106 3.990-63.097L3.907-63.097Q3.863-63.097 3.832-63.128Q3.801-63.159 3.801-63.207L3.801-66.204Q3.801-66.235 3.837-66.259Q3.872-66.283 3.898-66.283L3.938-66.283Q4.571-65.993 5.243-65.993Q5.915-65.993 6.557-66.283L6.583-66.283Q6.614-66.283 6.647-66.261Q6.680-66.239 6.680-66.204L6.680-66.103Q6.680-66.099 6.671-66.081Q6.662-66.063 6.662-66.059Q6.346-65.664 5.876-65.442Q5.405-65.220 4.909-65.220Q4.500-65.220 4.118-65.330L4.118-63.611Q4.575-64.068 5.287-64.068Q5.797-64.068 6.196-63.787Q6.596-63.506 6.818-63.051Q7.040-62.596 7.040-62.091Q7.040-61.541 6.761-61.082Q6.482-60.623 6.016-60.357Q5.550-60.091 5.006-60.091Q4.566-60.091 4.182-60.318Q3.797-60.544 3.569-60.924Q3.340-61.304 3.340-61.748Q3.340-61.941 3.472-62.073Q3.604-62.205 3.801-62.205Q3.933-62.205 4.037-62.146Q4.140-62.086 4.199-61.983Q4.258-61.880 4.258-61.748Q4.258-61.550 4.131-61.418Q4.004-61.287 3.801-61.287Q3.740-61.287 3.709-61.295",[741],[730,1304],{"fill":732,"d":1305},"m-28.27-16.143 8.247 14.138M51.253-26.146c0-6.285-5.096-11.38-11.381-11.38S28.49-32.432 28.49-26.147s5.095 11.381 11.38 11.381 11.382-5.095 11.382-11.38Zm-11.381 0",[725,1307,1309],{"transform":1308},"translate(34.676 37.043)",[730,1310],{"d":1311,"fill":727,"stroke":727,"className":1312,"style":1272},"M3.270-61.656Q3.270-62.214 3.630-62.627Q3.990-63.040 4.566-63.312L4.197-63.545Q3.894-63.747 3.707-64.077Q3.520-64.407 3.520-64.763Q3.520-65.417 4.026-65.850Q4.531-66.283 5.195-66.283Q5.594-66.283 5.979-66.123Q6.363-65.962 6.612-65.657Q6.860-65.352 6.860-64.934Q6.860-64.103 5.792-63.545L6.346-63.198Q6.693-62.970 6.904-62.601Q7.115-62.231 7.115-61.818Q7.115-61.440 6.957-61.122Q6.799-60.803 6.522-60.570Q6.245-60.337 5.902-60.214Q5.559-60.091 5.195-60.091Q4.729-60.091 4.283-60.278Q3.837-60.465 3.553-60.819Q3.270-61.172 3.270-61.656M3.793-61.656Q3.793-61.111 4.212-60.744Q4.632-60.377 5.195-60.377Q5.524-60.377 5.849-60.509Q6.175-60.641 6.383-60.895Q6.592-61.150 6.592-61.493Q6.592-61.757 6.456-61.981Q6.320-62.205 6.087-62.359L4.843-63.141Q4.382-62.904 4.087-62.517Q3.793-62.130 3.793-61.656M4.404-64.411L5.520-63.708Q5.744-63.831 5.948-64.020Q6.153-64.209 6.273-64.442Q6.394-64.675 6.394-64.934Q6.394-65.242 6.223-65.492Q6.051-65.743 5.775-65.883Q5.498-66.024 5.186-66.024Q4.737-66.024 4.364-65.778Q3.990-65.532 3.990-65.105Q3.990-64.701 4.404-64.411",[741],[730,1314],{"fill":732,"d":1315},"m11.393-52.434 19.97 18.433M31.336 7.998c0-6.286-5.095-11.381-11.381-11.381S8.574 1.712 8.574 7.997s5.095 11.382 11.38 11.382c6.287 0 11.382-5.096 11.382-11.381Zm-11.381 0",[725,1317,1319],{"transform":1318},"translate(14.76 71.187)",[730,1320],{"d":1321,"fill":727,"stroke":727,"className":1322,"style":1272},"M4.505-60.531Q4.505-61.168 4.661-61.814Q4.817-62.460 5.109-63.066Q5.401-63.673 5.810-64.222L6.627-65.330L5.599-65.330Q3.955-65.330 3.907-65.286Q3.801-65.158 3.683-64.455L3.397-64.455L3.692-66.371L3.982-66.371L3.982-66.345Q3.982-66.182 4.546-66.134Q5.111-66.085 5.656-66.085L7.374-66.085L7.374-65.879Q7.374-65.861 7.372-65.852Q7.370-65.844 7.365-65.835L6.078-64.086Q5.827-63.734 5.680-63.308Q5.533-62.882 5.467-62.418Q5.401-61.955 5.388-61.544Q5.375-61.133 5.375-60.531Q5.375-60.351 5.249-60.221Q5.124-60.091 4.944-60.091Q4.825-60.091 4.722-60.148Q4.619-60.206 4.562-60.309Q4.505-60.412 4.505-60.531",[741],[730,1324],{"fill":732,"d":1325},"M34.037-16.143 25.79-2.005M71.17 7.998c0-6.286-5.096-11.381-11.381-11.381S48.408 1.712 48.408 7.997s5.095 11.382 11.38 11.382S71.17 14.283 71.17 7.998Zm-11.381 0",[725,1327,1329],{"transform":1328},"translate(54.593 71.187)",[730,1330],{"d":1331,"fill":727,"stroke":727,"className":1332,"style":1272},"M3.946-60.676Q4.193-60.377 4.799-60.377Q5.080-60.377 5.320-60.515Q5.559-60.654 5.737-60.876Q5.915-61.098 6.025-61.361Q6.258-61.937 6.258-63.053Q6.091-62.688 5.786-62.464Q5.480-62.240 5.098-62.240Q4.562-62.240 4.146-62.519Q3.731-62.798 3.500-63.264Q3.270-63.730 3.270-64.257Q3.270-64.670 3.417-65.039Q3.564-65.409 3.828-65.685Q4.091-65.962 4.461-66.123Q4.830-66.283 5.243-66.283Q5.801-66.283 6.175-65.991Q6.548-65.699 6.752-65.235Q6.957-64.771 7.036-64.255Q7.115-63.739 7.115-63.207Q7.115-62.491 6.847-61.768Q6.579-61.045 6.056-60.568Q5.533-60.091 4.808-60.091Q4.258-60.091 3.881-60.340Q3.503-60.588 3.503-61.106Q3.503-61.225 3.560-61.328Q3.617-61.432 3.718-61.491Q3.819-61.550 3.946-61.550Q4.131-61.550 4.254-61.418Q4.377-61.287 4.377-61.106Q4.377-60.931 4.250-60.803Q4.122-60.676 3.946-60.676M5.142-62.504Q5.511-62.504 5.759-62.746Q6.008-62.987 6.124-63.345Q6.240-63.704 6.240-64.077Q6.240-64.187 6.232-64.240Q6.236-64.253 6.238-64.264Q6.240-64.275 6.240-64.292Q6.240-64.947 6.025-65.486Q5.810-66.024 5.243-66.024Q4.883-66.024 4.654-65.874Q4.425-65.725 4.309-65.468Q4.193-65.211 4.160-64.930Q4.127-64.648 4.127-64.275L4.127-64.240Q4.127-63.914 4.153-63.627Q4.179-63.339 4.278-63.080Q4.377-62.820 4.588-62.662Q4.799-62.504 5.142-62.504",[741],[730,1334],{"fill":732,"d":1335},"m45.707-16.143 8.247 14.138",[725,1337,1340],{"stroke":1338,"style":1339},"var(--tk-warn)","stroke-width:1.2",[730,1341],{"fill":732,"d":1342},"M51.253-26.146c0-6.285-5.096-11.38-11.381-11.38S28.49-32.432 28.49-26.147s5.095 11.381 11.38 11.381 11.382-5.095 11.382-11.38Zm-11.381 0",[725,1344,1345],{"fill":1338,"stroke":1338},[725,1346,1347,1355,1361,1367,1373,1379],{"fill":1338,"stroke":732,"fontSize":937},[725,1348,1350],{"transform":1349},"translate(87.605 39.718)",[730,1351],{"d":1352,"fill":1338,"stroke":1338,"className":1353,"style":1354},"M12.207-69.051L12.176-69.051Q12.313-68.754 12.610-68.578Q12.907-68.402 13.235-68.402Q13.598-68.402 13.825-68.580Q14.052-68.757 14.146-69.046Q14.240-69.335 14.240-69.697Q14.240-70.012 14.186-70.297Q14.131-70.582 13.958-70.788Q13.786-70.993 13.471-70.993Q13.198-70.993 13.015-70.926Q12.832-70.859 12.728-70.770Q12.624-70.682 12.528-70.572Q12.432-70.463 12.388-70.453L12.309-70.453Q12.237-70.470 12.220-70.541L12.220-72.859Q12.220-72.893 12.244-72.915Q12.268-72.937 12.302-72.937L12.330-72.937Q12.617-72.821 12.885-72.767Q13.153-72.712 13.430-72.712Q13.707-72.712 13.977-72.767Q14.247-72.821 14.527-72.937L14.551-72.937Q14.586-72.937 14.609-72.914Q14.633-72.890 14.633-72.859L14.633-72.790Q14.633-72.763 14.613-72.743Q14.339-72.428 13.955-72.252Q13.570-72.076 13.157-72.076Q12.818-72.076 12.501-72.162L12.501-70.880Q12.897-71.215 13.471-71.215Q13.875-71.215 14.211-71.005Q14.548-70.794 14.741-70.442Q14.934-70.090 14.934-69.690Q14.934-69.359 14.794-69.073Q14.654-68.788 14.410-68.578Q14.165-68.368 13.863-68.258Q13.560-68.149 13.242-68.149Q12.883-68.149 12.557-68.313Q12.231-68.477 12.036-68.769Q11.841-69.061 11.841-69.424Q11.841-69.574 11.947-69.680Q12.053-69.786 12.207-69.786Q12.360-69.786 12.465-69.682Q12.569-69.578 12.569-69.424Q12.569-69.267 12.465-69.159Q12.360-69.051 12.207-69.051",[741],"stroke-width:0.210",[725,1356,1357],{"transform":1349},[730,1358],{"d":1359,"fill":1338,"stroke":1338,"className":1360,"style":1354},"M21.532-67.769L17.144-69.885Q17.051-69.930 17.051-70.039Q17.051-70.142 17.144-70.186L21.532-72.302Q21.594-72.322 21.614-72.322Q21.686-72.322 21.736-72.269Q21.785-72.216 21.785-72.144Q21.785-72.107 21.761-72.062Q21.737-72.018 21.700-71.997L17.619-70.039L21.700-68.074Q21.731-68.060 21.758-68.012Q21.785-67.964 21.785-67.927Q21.785-67.862 21.736-67.805Q21.686-67.749 21.614-67.749Q21.594-67.749 21.532-67.769",[741],[725,1362,1363],{"transform":1349},[730,1364],{"d":1365,"fill":1338,"stroke":1338,"className":1366,"style":1354},"M25.446-68.149Q24.988-68.149 24.670-68.364Q24.353-68.580 24.171-68.932Q23.990-69.284 23.913-69.704Q23.836-70.124 23.836-70.552Q23.836-71.136 24.089-71.692Q24.342-72.247 24.812-72.592Q25.282-72.937 25.880-72.937Q26.290-72.937 26.574-72.739Q26.858-72.541 26.858-72.138Q26.858-72.042 26.812-71.963Q26.766-71.885 26.685-71.840Q26.605-71.796 26.516-71.796Q26.369-71.796 26.268-71.893Q26.167-71.991 26.167-72.138Q26.167-72.268 26.258-72.375Q26.349-72.483 26.482-72.483Q26.294-72.705 25.880-72.705Q25.566-72.705 25.292-72.541Q25.019-72.377 24.852-72.103Q24.664-71.813 24.599-71.447Q24.534-71.081 24.534-70.627Q24.684-70.921 24.949-71.099Q25.214-71.276 25.528-71.276Q25.959-71.276 26.308-71.070Q26.656-70.863 26.856-70.507Q27.056-70.152 27.056-69.725Q27.056-69.280 26.839-68.920Q26.622-68.559 26.249-68.354Q25.877-68.149 25.446-68.149M25.446-68.402Q25.822-68.402 26.026-68.585Q26.229-68.768 26.292-69.051Q26.355-69.335 26.355-69.725Q26.355-70.111 26.301-70.391Q26.246-70.671 26.051-70.863Q25.856-71.054 25.487-71.054Q25.197-71.054 24.985-70.878Q24.773-70.702 24.665-70.429Q24.558-70.155 24.558-69.872L24.558-69.731L24.558-69.690Q24.558-69.185 24.770-68.793Q24.981-68.402 25.446-68.402M28.153-68.709Q28.153-68.877 28.276-69Q28.399-69.123 28.574-69.123Q28.741-69.123 28.864-69Q28.987-68.877 28.987-68.709Q28.987-68.535 28.864-68.412Q28.741-68.289 28.574-68.289Q28.399-68.289 28.276-68.412Q28.153-68.535 28.153-68.709M28.153-70.893Q28.153-71.061 28.276-71.184Q28.399-71.307 28.574-71.307Q28.741-71.307 28.864-71.184Q28.987-71.061 28.987-70.893Q28.987-70.719 28.864-70.596Q28.741-70.473 28.574-70.473Q28.399-70.473 28.276-70.596Q28.153-70.719 28.153-70.893",[741],[725,1368,1369],{"transform":1349},[730,1370],{"d":1371,"fill":1338,"stroke":1338,"className":1372,"style":1354},"M3.197-61.800Q3.197-62.138 3.338-62.429Q3.478-62.719 3.722-62.933Q3.966-63.146 4.271-63.261Q4.575-63.375 4.900-63.375Q5.170-63.375 5.433-63.276Q5.696-63.177 5.887-62.999L5.887-64.397Q5.887-64.667 5.780-64.729Q5.672-64.790 5.361-64.790L5.361-65.071L6.438-65.146L6.438-60.962Q6.438-60.774 6.492-60.691Q6.547-60.607 6.648-60.588Q6.749-60.569 6.964-60.569L6.964-60.289L5.857-60.221L5.857-60.638Q5.440-60.221 4.814-60.221Q4.383-60.221 4.011-60.433Q3.638-60.644 3.418-61.005Q3.197-61.366 3.197-61.800M4.872-60.443Q5.081-60.443 5.267-60.515Q5.453-60.586 5.607-60.723Q5.761-60.860 5.857-61.038L5.857-62.647Q5.771-62.794 5.626-62.914Q5.481-63.034 5.311-63.093Q5.142-63.153 4.961-63.153Q4.401-63.153 4.132-62.764Q3.864-62.374 3.864-61.793Q3.864-61.222 4.098-60.832Q4.332-60.443 4.872-60.443M9.363-60.289L7.627-60.289L7.627-60.569Q7.856-60.569 8.005-60.603Q8.154-60.638 8.154-60.778L8.154-62.627Q8.154-62.897 8.046-62.958Q7.938-63.020 7.627-63.020L7.627-63.300L8.656-63.375L8.656-62.668Q8.786-62.976 9.029-63.175Q9.271-63.375 9.589-63.375Q9.808-63.375 9.979-63.251Q10.150-63.126 10.150-62.914Q10.150-62.777 10.050-62.678Q9.951-62.579 9.818-62.579Q9.681-62.579 9.582-62.678Q9.483-62.777 9.483-62.914Q9.483-63.054 9.582-63.153Q9.292-63.153 9.092-62.957Q8.892-62.760 8.800-62.466Q8.707-62.172 8.707-61.892L8.707-60.778Q8.707-60.569 9.363-60.569L9.363-60.289M10.693-61.772Q10.693-62.114 10.828-62.413Q10.963-62.712 11.202-62.936Q11.442-63.160 11.759-63.285Q12.077-63.410 12.409-63.410Q12.853-63.410 13.253-63.194Q13.653-62.979 13.887-62.601Q14.121-62.224 14.121-61.772Q14.121-61.431 13.979-61.147Q13.838-60.863 13.593-60.656Q13.349-60.450 13.039-60.335Q12.730-60.221 12.409-60.221Q11.978-60.221 11.577-60.422Q11.175-60.624 10.934-60.976Q10.693-61.328 10.693-61.772M12.409-60.470Q13.010-60.470 13.234-60.848Q13.458-61.226 13.458-61.858Q13.458-62.470 13.224-62.829Q12.990-63.187 12.409-63.187Q11.356-63.187 11.356-61.858Q11.356-61.226 11.582-60.848Q11.807-60.470 12.409-60.470M16.360-58.932L14.730-58.932L14.730-59.212Q14.959-59.212 15.107-59.247Q15.256-59.281 15.256-59.421L15.256-62.767Q15.256-62.938 15.119-62.979Q14.983-63.020 14.730-63.020L14.730-63.300L15.810-63.375L15.810-62.969Q16.032-63.170 16.319-63.273Q16.606-63.375 16.914-63.375Q17.341-63.375 17.705-63.162Q18.069-62.948 18.283-62.584Q18.496-62.220 18.496-61.800Q18.496-61.355 18.257-60.991Q18.018-60.627 17.625-60.424Q17.232-60.221 16.787-60.221Q16.521-60.221 16.273-60.321Q16.025-60.422 15.837-60.603L15.837-59.421Q15.837-59.284 15.986-59.248Q16.134-59.212 16.360-59.212L16.360-58.932M15.837-62.620L15.837-61.010Q15.970-60.757 16.213-60.600Q16.456-60.443 16.733-60.443Q17.061-60.443 17.314-60.644Q17.567-60.846 17.700-61.164Q17.833-61.482 17.833-61.800Q17.833-62.029 17.768-62.258Q17.703-62.487 17.575-62.685Q17.447-62.883 17.252-63.003Q17.057-63.122 16.825-63.122Q16.531-63.122 16.263-62.993Q15.994-62.863 15.837-62.620",[741],[725,1374,1375],{"transform":1349},[730,1376],{"d":1377,"fill":1338,"stroke":1338,"className":1378,"style":1354},"M23.586-60.289L21.850-60.289L21.850-60.569Q22.079-60.569 22.228-60.603Q22.376-60.638 22.376-60.778L22.376-62.627Q22.376-62.897 22.269-62.958Q22.161-63.020 21.850-63.020L21.850-63.300L22.879-63.375L22.879-62.668Q23.009-62.976 23.251-63.175Q23.494-63.375 23.812-63.375Q24.031-63.375 24.202-63.251Q24.373-63.126 24.373-62.914Q24.373-62.777 24.273-62.678Q24.174-62.579 24.041-62.579Q23.904-62.579 23.805-62.678Q23.706-62.777 23.706-62.914Q23.706-63.054 23.805-63.153Q23.515-63.153 23.315-62.957Q23.115-62.760 23.022-62.466Q22.930-62.172 22.930-61.892L22.930-60.778Q22.930-60.569 23.586-60.569L23.586-60.289M26.574-60.289L25.022-60.289L25.022-60.569Q25.248-60.569 25.396-60.603Q25.545-60.638 25.545-60.778L25.545-62.627Q25.545-62.815 25.497-62.899Q25.449-62.982 25.352-63.001Q25.254-63.020 25.043-63.020L25.043-63.300L26.099-63.375L26.099-60.778Q26.099-60.638 26.230-60.603Q26.362-60.569 26.574-60.569L26.574-60.289M25.302-64.596Q25.302-64.767 25.425-64.886Q25.548-65.006 25.719-65.006Q25.887-65.006 26.010-64.886Q26.133-64.767 26.133-64.596Q26.133-64.421 26.010-64.298Q25.887-64.175 25.719-64.175Q25.548-64.175 25.425-64.298Q25.302-64.421 25.302-64.596M27.179-59.756Q27.179-60.002 27.375-60.186Q27.572-60.371 27.828-60.450Q27.691-60.562 27.620-60.723Q27.548-60.884 27.548-61.065Q27.548-61.386 27.760-61.632Q27.425-61.930 27.425-62.340Q27.425-62.801 27.814-63.088Q28.204-63.375 28.683-63.375Q29.154-63.375 29.489-63.129Q29.664-63.283 29.874-63.365Q30.084-63.447 30.313-63.447Q30.477-63.447 30.598-63.340Q30.720-63.232 30.720-63.068Q30.720-62.972 30.648-62.900Q30.576-62.829 30.484-62.829Q30.385-62.829 30.315-62.902Q30.245-62.976 30.245-63.075Q30.245-63.129 30.258-63.160L30.265-63.174Q30.272-63.194 30.281-63.205Q30.289-63.215 30.293-63.222Q29.937-63.222 29.650-62.999Q29.937-62.706 29.937-62.340Q29.937-62.025 29.752-61.793Q29.568-61.560 29.279-61.432Q28.990-61.304 28.683-61.304Q28.481-61.304 28.290-61.354Q28.098-61.403 27.920-61.513Q27.828-61.386 27.828-61.243Q27.828-61.061 27.956-60.926Q28.084-60.791 28.269-60.791L28.901-60.791Q29.349-60.791 29.718-60.720Q30.087-60.648 30.347-60.419Q30.607-60.190 30.607-59.756Q30.607-59.435 30.311-59.233Q30.016-59.031 29.612-58.942Q29.209-58.853 28.895-58.853Q28.577-58.853 28.173-58.942Q27.770-59.031 27.474-59.233Q27.179-59.435 27.179-59.756M27.633-59.756Q27.633-59.527 27.852-59.378Q28.071-59.229 28.363-59.161Q28.655-59.093 28.895-59.093Q29.059-59.093 29.267-59.129Q29.476-59.164 29.682-59.245Q29.889-59.325 30.021-59.453Q30.152-59.581 30.152-59.756Q30.152-60.108 29.771-60.202Q29.390-60.296 28.888-60.296L28.269-60.296Q28.030-60.296 27.832-60.145Q27.633-59.995 27.633-59.756M28.683-61.543Q29.349-61.543 29.349-62.340Q29.349-63.140 28.683-63.140Q28.013-63.140 28.013-62.340Q28.013-61.543 28.683-61.543M32.883-60.289L31.250-60.289L31.250-60.569Q31.479-60.569 31.627-60.603Q31.776-60.638 31.776-60.778L31.776-64.397Q31.776-64.667 31.668-64.729Q31.561-64.790 31.250-64.790L31.250-65.071L32.330-65.146L32.330-62.760Q32.436-62.945 32.613-63.087Q32.791-63.228 33-63.302Q33.208-63.375 33.434-63.375Q33.939-63.375 34.223-63.152Q34.507-62.928 34.507-62.432L34.507-60.778Q34.507-60.641 34.656-60.605Q34.804-60.569 35.030-60.569L35.030-60.289L33.399-60.289L33.399-60.569Q33.628-60.569 33.777-60.603Q33.926-60.638 33.926-60.778L33.926-62.418Q33.926-62.753 33.806-62.953Q33.687-63.153 33.372-63.153Q33.102-63.153 32.868-63.017Q32.634-62.880 32.495-62.646Q32.357-62.412 32.357-62.138L32.357-60.778Q32.357-60.641 32.507-60.605Q32.658-60.569 32.883-60.569",[741],[725,1380,1381],{"transform":1349},[730,1382],{"d":1383,"fill":1338,"stroke":1338,"className":1384,"style":1354},"M35.940-61.130L35.940-63.027L35.301-63.027L35.301-63.249Q35.619-63.249 35.836-63.459Q36.053-63.669 36.153-63.979Q36.254-64.288 36.254-64.596L36.521-64.596L36.521-63.307L37.598-63.307L37.598-63.027L36.521-63.027L36.521-61.143Q36.521-60.867 36.625-60.668Q36.729-60.470 36.989-60.470Q37.146-60.470 37.252-60.574Q37.358-60.679 37.408-60.832Q37.457-60.986 37.457-61.143L37.457-61.557L37.724-61.557L37.724-61.130Q37.724-60.904 37.625-60.694Q37.526-60.484 37.341-60.352Q37.157-60.221 36.928-60.221Q36.490-60.221 36.215-60.458Q35.940-60.696 35.940-61.130",[741],[725,1386,1387,1390],{"fill":1338,"stroke":1338},[730,1388],{"fill":732,"d":1389},"M79.706-26.146H53.453",[730,1391],{"stroke":732,"d":1392},"m51.453-26.146 3.2 1.6-1.2-1.6 1.2-1.6",[725,1394,1396],{"stroke":1395,"style":1339},"var(--tk-accent)",[730,1397],{"fill":732,"d":1264},[725,1399,1400],{"stroke":1395,"style":1339},[730,1401],{"fill":732,"d":1275},[725,1403,1404],{"stroke":1395,"style":1339},[730,1405],{"fill":732,"d":1406},"M-2.807 7.998c0-6.286-5.096-11.381-11.381-11.381S-25.57 1.712-25.57 7.997s5.096 11.382 11.382 11.382 11.38-5.096 11.38-11.381Zm-11.381 0",[725,1408,1410,1413],{"fill":1395,"stroke":1395,"style":1409},"stroke-width:.8",[730,1411],{"fill":732,"d":1412},"M-7.073-54.375c-9.323 5.538-14.077 9.926-18.84 16.655",[730,1414],{"stroke":732,"d":1415},"m-27.415-35.598 4.1-2.194-2.598.072-.797-2.475",[725,1417,1418,1421],{"fill":1395,"stroke":1395,"style":1409},[730,1419],{"fill":732,"d":1420},"M-30.478-15.148c2.07 6.276 4.058 9.683 6.754 12.65",[730,1422],{"stroke":732,"d":1423},"m-21.976-.573-1.258-4.478-.49 2.553-2.588.244",[807,1425,1427,1428,1462,1463,1478,1479,1513,1514,1529,1530,1513,1564,1579,1580,1595,1596,1611],{"className":1426},[810],"Searching for ",[390,1429,1431],{"className":1430},[393],[390,1432,1434,1453],{"className":1433,"ariaHidden":398},[397],[390,1435,1437,1440,1443,1446,1450],{"className":1436},[402],[390,1438],{"className":1439,"style":1038},[406],[390,1441,551],{"className":1442,"style":550},[411,412],[390,1444],{"className":1445,"style":569},[568],[390,1447,1449],{"className":1448},[573],"=",[390,1451],{"className":1452,"style":569},[568],[390,1454,1456,1459],{"className":1455},[402],[390,1457],{"className":1458,"style":827},[406],[390,1460,881],{"className":1461},[411],". At ",[390,1464,1466],{"className":1465},[393],[390,1467,1469],{"className":1468,"ariaHidden":398},[397],[390,1470,1472,1475],{"className":1471},[402],[390,1473],{"className":1474,"style":827},[406],[390,1476,831],{"className":1477},[411]," we go left (",[390,1480,1482],{"className":1481},[393],[390,1483,1485,1504],{"className":1484,"ariaHidden":398},[397],[390,1486,1488,1492,1495,1498,1501],{"className":1487},[402],[390,1489],{"className":1490,"style":1491},[406],"height:0.6835em;vertical-align:-0.0391em;",[390,1493,881],{"className":1494},[411],[390,1496],{"className":1497,"style":569},[568],[390,1499,1145],{"className":1500},[573],[390,1502],{"className":1503,"style":569},[568],[390,1505,1507,1510],{"className":1506},[402],[390,1508],{"className":1509,"style":827},[406],[390,1511,831],{"className":1512},[411],"); at ",[390,1515,1517],{"className":1516},[393],[390,1518,1520],{"className":1519,"ariaHidden":398},[397],[390,1521,1523,1526],{"className":1522},[402],[390,1524],{"className":1525,"style":827},[406],[390,1527,871],{"className":1528},[411]," we go right (",[390,1531,1533],{"className":1532},[393],[390,1534,1536,1555],{"className":1535,"ariaHidden":398},[397],[390,1537,1539,1542,1545,1548,1552],{"className":1538},[402],[390,1540],{"className":1541,"style":1491},[406],[390,1543,881],{"className":1544},[411],[390,1546],{"className":1547,"style":569},[568],[390,1549,1551],{"className":1550},[573],">",[390,1553],{"className":1554,"style":569},[568],[390,1556,1558,1561],{"className":1557},[402],[390,1559],{"className":1560,"style":827},[406],[390,1562,871],{"className":1563},[411],[390,1565,1567],{"className":1566},[393],[390,1568,1570],{"className":1569,"ariaHidden":398},[397],[390,1571,1573,1576],{"className":1572},[402],[390,1574],{"className":1575,"style":827},[406],[390,1577,881],{"className":1578},[411]," we stop. The path (accent) visits one node per level, and each step discards an entire subtree (red), so the search examines just ",[390,1581,1583],{"className":1582},[393],[390,1584,1586],{"className":1585,"ariaHidden":398},[397],[390,1587,1589,1592],{"className":1588},[402],[390,1590],{"className":1591,"style":827},[406],[390,1593,871],{"className":1594},[411]," of the ",[390,1597,1599],{"className":1598},[393],[390,1600,1602],{"className":1601,"ariaHidden":398},[397],[390,1603,1605,1608],{"className":1604},[402],[390,1606],{"className":1607,"style":827},[406],[390,1609,937],{"className":1610},[411]," nodes.",[381,1613,1614,1004,1640,1662,1663,1665,1666,1668],{},[390,1615,1617],{"className":1616},[393],[390,1618,1620],{"className":1619,"ariaHidden":398},[397],[390,1621,1623,1627],{"className":1622},[402],[390,1624],{"className":1625,"style":1626},[406],"height:0.6833em;",[390,1628,1632],{"className":1629},[1630,1631],"enclosing","textsc",[390,1633,1636],{"className":1634},[411,1635],"text",[390,1637,1639],{"className":1638},[411],"Tree-Minimum",[390,1641,1643],{"className":1642},[393],[390,1644,1646],{"className":1645,"ariaHidden":398},[397],[390,1647,1649,1652],{"className":1648},[402],[390,1650],{"className":1651,"style":1626},[406],[390,1653,1655],{"className":1654},[1630,1631],[390,1656,1658],{"className":1657},[411,1635],[390,1659,1661],{"className":1660},[411],"Tree-Maximum"," are the degenerate\ncases of search: follow ",[1082,1664,517],{}," pointers until they run out to reach the smallest\nkey, or ",[1082,1667,618],{}," pointers for the largest.",[1076,1670,1672],{"className":1078,"code":1671,"language":1080,"meta":376,"style":376},"caption: $\\textsc{Tree-Minimum}(x)$ and $\\textsc{Tree-Maximum}(x)$\nTree-Minimum(x):\n  while $left(x) \\ne \\text{nil}$ do\n    $x \\gets left(x)$ \u002F\u002F min is the leftmost node\n  return $x$\nTree-Maximum(x):\n  while $right(x) \\ne \\text{nil}$ do\n    $x \\gets right(x)$ \u002F\u002F max is the rightmost node\n  return $x$\n",[1082,1673,1674,1679,1684,1689,1694,1698,1703,1708,1713],{"__ignoreMap":376},[390,1675,1676],{"class":1086,"line":6},[390,1677,1678],{},"caption: $\\textsc{Tree-Minimum}(x)$ and $\\textsc{Tree-Maximum}(x)$\n",[390,1680,1681],{"class":1086,"line":18},[390,1682,1683],{},"Tree-Minimum(x):\n",[390,1685,1686],{"class":1086,"line":24},[390,1687,1688],{},"  while $left(x) \\ne \\text{nil}$ do\n",[390,1690,1691],{"class":1086,"line":73},[390,1692,1693],{},"    $x \\gets left(x)$ \u002F\u002F min is the leftmost node\n",[390,1695,1696],{"class":1086,"line":102},[390,1697,1099],{},[390,1699,1700],{"class":1086,"line":108},[390,1701,1702],{},"Tree-Maximum(x):\n",[390,1704,1705],{"class":1086,"line":116},[390,1706,1707],{},"  while $right(x) \\ne \\text{nil}$ do\n",[390,1709,1710],{"class":1086,"line":196},[390,1711,1712],{},"    $x \\gets right(x)$ \u002F\u002F max is the rightmost node\n",[390,1714,1715],{"class":1086,"line":202},[390,1716,1099],{},[445,1718,1720],{"id":1719},"inserting","Inserting",[381,1722,1723,1724,1739,1740,1743,1744,1759],{},"Insertion reuses the search path. To insert key ",[390,1725,1727],{"className":1726},[393],[390,1728,1730],{"className":1729,"ariaHidden":398},[397],[390,1731,1733,1736],{"className":1732},[402],[390,1734],{"className":1735,"style":1038},[406],[390,1737,551],{"className":1738,"style":550},[411,412],", walk down as if searching\nfor it; when the walk falls off the bottom of the tree (reaches a ",[1082,1741,1742],{},"nil"," child),\nthat empty spot is exactly where ",[390,1745,1747],{"className":1746},[393],[390,1748,1750],{"className":1749,"ariaHidden":398},[397],[390,1751,1753,1756],{"className":1752},[402],[390,1754],{"className":1755,"style":1038},[406],[390,1757,551],{"className":1758,"style":550},[411,412]," belongs, preserving the BST property. We\nattach a new leaf there, remembering the parent so we can hook it in.",[1076,1761,1763],{"className":1078,"code":1762,"language":1080,"meta":376,"style":376},"caption: $\\textsc{Tree-Insert}(T, z)$ — insert node $z$ (with $key(z)$ set) into BST $T$\n$y \\gets \\text{nil}$ \u002F\u002F y trails x\n$x \\gets root(T)$\nwhile $x \\ne \\text{nil}$ do\n  $y \\gets x$\n  if $key(z) \u003C key(x)$ then\n    $x \\gets left(x)$\n  else\n    $x \\gets right(x)$\n$parent(z) \\gets y$\nif $y = \\text{nil}$ then\n  $root(T) \\gets z$ \u002F\u002F tree was empty\nelse if $key(z) \u003C key(y)$ then\n  $left(y) \\gets z$\nelse\n  $right(y) \\gets z$\n",[1082,1764,1765,1770,1775,1780,1785,1790,1795,1800,1805,1810,1815,1820,1825,1831,1837,1842],{"__ignoreMap":376},[390,1766,1767],{"class":1086,"line":6},[390,1768,1769],{},"caption: $\\textsc{Tree-Insert}(T, z)$ — insert node $z$ (with $key(z)$ set) into BST $T$\n",[390,1771,1772],{"class":1086,"line":18},[390,1773,1774],{},"$y \\gets \\text{nil}$ \u002F\u002F y trails x\n",[390,1776,1777],{"class":1086,"line":24},[390,1778,1779],{},"$x \\gets root(T)$\n",[390,1781,1782],{"class":1086,"line":73},[390,1783,1784],{},"while $x \\ne \\text{nil}$ do\n",[390,1786,1787],{"class":1086,"line":102},[390,1788,1789],{},"  $y \\gets x$\n",[390,1791,1792],{"class":1086,"line":108},[390,1793,1794],{},"  if $key(z) \u003C key(x)$ then\n",[390,1796,1797],{"class":1086,"line":116},[390,1798,1799],{},"    $x \\gets left(x)$\n",[390,1801,1802],{"class":1086,"line":196},[390,1803,1804],{},"  else\n",[390,1806,1807],{"class":1086,"line":202},[390,1808,1809],{},"    $x \\gets right(x)$\n",[390,1811,1812],{"class":1086,"line":283},[390,1813,1814],{},"$parent(z) \\gets y$\n",[390,1816,1817],{"class":1086,"line":333},[390,1818,1819],{},"if $y = \\text{nil}$ then\n",[390,1821,1822],{"class":1086,"line":354},[390,1823,1824],{},"  $root(T) \\gets z$ \u002F\u002F tree was empty\n",[390,1826,1828],{"class":1086,"line":1827},13,[390,1829,1830],{},"else if $key(z) \u003C key(y)$ then\n",[390,1832,1834],{"class":1086,"line":1833},14,[390,1835,1836],{},"  $left(y) \\gets z$\n",[390,1838,1840],{"class":1086,"line":1839},15,[390,1841,1114],{},[390,1843,1845],{"class":1086,"line":1844},16,[390,1846,1847],{},"  $right(y) \\gets z$\n",[381,1849,1850,1851,1875,1876,1879],{},"Like search, insertion walks one root-to-leaf path and costs ",[390,1852,1854],{"className":1853},[393],[390,1855,1857],{"className":1856,"ariaHidden":398},[397],[390,1858,1860,1863,1866,1869,1872],{"className":1859},[402],[390,1861],{"className":1862,"style":407},[406],[390,1864,414],{"className":1865,"style":413},[411,412],[390,1867,419],{"className":1868},[418],[390,1870,1224],{"className":1871},[411,412],[390,1873,428],{"className":1874},[427],". New keys\nalways enter as ",[431,1877,1878],{},"leaves",", which is what keeps insertion simple, but also what\nsets up the trouble we meet below.",[445,1881,1883],{"id":1882},"finding-a-successor","Finding a successor",[381,1885,1886,1887,1890,1891,1906,1907,1934],{},"The ",[431,1888,1889],{},"successor"," of a node ",[390,1892,1894],{"className":1893},[393],[390,1895,1897],{"className":1896,"ariaHidden":398},[397],[390,1898,1900,1903],{"className":1899},[402],[390,1901],{"className":1902,"style":464},[406],[390,1904,468],{"className":1905},[411,412]," is the node with the smallest key greater than\n",[390,1908,1910],{"className":1909},[393],[390,1911,1913],{"className":1912,"ariaHidden":398},[397],[390,1914,1916,1919,1922,1925,1928,1931],{"className":1915},[402],[390,1917],{"className":1918,"style":407},[406],[390,1920,551],{"className":1921,"style":550},[411,412],[390,1923,555],{"className":1924,"style":512},[411,412],[390,1926,419],{"className":1927},[418],[390,1929,468],{"className":1930},[411,412],[390,1932,428],{"className":1933},[427],", the next key in sorted order. There are two cases, and neither needs\na comparison of keys, only structure:",[1936,1937,1938,1989],"ul",{},[1939,1940,1941,1942,1957,1958,1961,1962,443],"li",{},"If ",[390,1943,1945],{"className":1944},[393],[390,1946,1948],{"className":1947,"ariaHidden":398},[397],[390,1949,1951,1954],{"className":1950},[402],[390,1952],{"className":1953,"style":464},[406],[390,1955,468],{"className":1956},[411,412]," has a right subtree, the successor is the ",[436,1959,1960],{},"minimum"," of that subtree:\nthe smallest key still larger than ",[390,1963,1965],{"className":1964},[393],[390,1966,1968],{"className":1967,"ariaHidden":398},[397],[390,1969,1971,1974,1977,1980,1983,1986],{"className":1970},[402],[390,1972],{"className":1973,"style":407},[406],[390,1975,551],{"className":1976,"style":550},[411,412],[390,1978,555],{"className":1979,"style":512},[411,412],[390,1981,419],{"className":1982},[418],[390,1984,468],{"className":1985},[411,412],[390,1987,428],{"className":1988},[427],[1939,1990,1941,1991,2006,2007,2022,2023,2025],{},[390,1992,1994],{"className":1993},[393],[390,1995,1997],{"className":1996,"ariaHidden":398},[397],[390,1998,2000,2003],{"className":1999},[402],[390,2001],{"className":2002,"style":464},[406],[390,2004,468],{"className":2005},[411,412]," has no right subtree, the successor is the lowest ancestor whose left\nchild is also an ancestor of ",[390,2008,2010],{"className":2009},[393],[390,2011,2013],{"className":2012,"ariaHidden":398},[397],[390,2014,2016,2019],{"className":2015},[402],[390,2017],{"className":2018,"style":464},[406],[390,2020,468],{"className":2021},[411,412],"; we climb up until we move up a ",[436,2024,517],{}," link.",[1076,2027,2029],{"className":1078,"code":2028,"language":1080,"meta":376,"style":376},"caption: $\\textsc{Tree-Successor}(x)$ — next node in sorted order\nif $right(x) \\ne \\text{nil}$ then\n  return call $\\textsc{Tree-Minimum}(right(x))$ \u002F\u002F min of right subtree\n$y \\gets parent(x)$\nwhile $y \\ne \\text{nil}$ and $x = right(y)$ do\n  $x \\gets y$ \u002F\u002F climb while x is a right child\n  $y \\gets parent(y)$\nreturn $y$\n",[1082,2030,2031,2036,2041,2046,2051,2056,2061,2066],{"__ignoreMap":376},[390,2032,2033],{"class":1086,"line":6},[390,2034,2035],{},"caption: $\\textsc{Tree-Successor}(x)$ — next node in sorted order\n",[390,2037,2038],{"class":1086,"line":18},[390,2039,2040],{},"if $right(x) \\ne \\text{nil}$ then\n",[390,2042,2043],{"class":1086,"line":24},[390,2044,2045],{},"  return call $\\textsc{Tree-Minimum}(right(x))$ \u002F\u002F min of right subtree\n",[390,2047,2048],{"class":1086,"line":73},[390,2049,2050],{},"$y \\gets parent(x)$\n",[390,2052,2053],{"class":1086,"line":102},[390,2054,2055],{},"while $y \\ne \\text{nil}$ and $x = right(y)$ do\n",[390,2057,2058],{"class":1086,"line":108},[390,2059,2060],{},"  $x \\gets y$ \u002F\u002F climb while x is a right child\n",[390,2062,2063],{"class":1086,"line":116},[390,2064,2065],{},"  $y \\gets parent(y)$\n",[390,2067,2068],{"class":1086,"line":196},[390,2069,2070],{},"return $y$\n",[381,2072,2073,2074,2096,2097,2121,2122,2125],{},"Both cases follow a single vertical path, down into the right subtree or up\nthrough ancestors, so ",[390,2075,2077],{"className":2076},[393],[390,2078,2080],{"className":2079,"ariaHidden":398},[397],[390,2081,2083,2086],{"className":2082},[402],[390,2084],{"className":2085,"style":1626},[406],[390,2087,2089],{"className":2088},[1630,1631],[390,2090,2092],{"className":2091},[411,1635],[390,2093,2095],{"className":2094},[411],"Tree-Successor"," also runs in ",[390,2098,2100],{"className":2099},[393],[390,2101,2103],{"className":2102,"ariaHidden":398},[397],[390,2104,2106,2109,2112,2115,2118],{"className":2105},[402],[390,2107],{"className":2108,"style":407},[406],[390,2110,414],{"className":2111,"style":413},[411,412],[390,2113,419],{"className":2114},[418],[390,2116,1224],{"className":2117},[411,412],[390,2119,428],{"className":2120},[427],". ",[431,2123,2124],{},"Predecessor","\nis the mirror image (left subtree's maximum, or climb until a right link).",[712,2127,2129,2324],{"className":2128},[715,716],[718,2130,2134],{"xmlns":720,"width":2131,"height":2132,"viewBox":2133},"404.379","119.617","-75 -75 303.285 89.713",[725,2135,2136,2139,2145,2148,2155,2158,2165,2168,2175,2178,2185,2188,2195,2198,2205,2208,2212,2217,2225,2233,2236,2242,2245,2251,2254,2260,2263,2269,2272,2278,2281,2287,2290,2296,2299,2304,2308,2316],{"stroke":727,"style":728},[730,2137],{"fill":732,"d":2138},"M-1.385-61.712c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.458-9.959 9.958 4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2140,2141],{"transform":1267},[730,2142],{"d":2143,"fill":727,"stroke":727,"className":2144,"style":1272},"M-9.031-61.514Q-9.765-61.514-10.196-61.995Q-10.627-62.477-10.791-63.169Q-10.956-63.861-10.956-64.608Q-10.956-65.337-10.664-66.060Q-10.372-66.783-9.818-67.245Q-9.264-67.706-8.517-67.706Q-8.021-67.706-7.685-67.440Q-7.348-67.174-7.348-66.691Q-7.348-66.511-7.476-66.383Q-7.603-66.256-7.779-66.256Q-7.959-66.256-8.089-66.381Q-8.218-66.506-8.218-66.691Q-8.218-66.805-8.161-66.909Q-8.104-67.012-8.003-67.071Q-7.902-67.130-7.779-67.130Q-7.775-67.130-7.770-67.128Q-7.766-67.126-7.761-67.122Q-7.876-67.289-8.084-67.368Q-8.293-67.447-8.517-67.447Q-8.961-67.447-9.319-67.146Q-9.677-66.845-9.866-66.392Q-10.099-65.786-10.099-64.753Q-9.928-65.118-9.627-65.346Q-9.326-65.575-8.939-65.575Q-8.535-65.575-8.190-65.408Q-7.845-65.241-7.608-64.960Q-7.370-64.678-7.241-64.316Q-7.111-63.953-7.111-63.549Q-7.111-63.004-7.355-62.538Q-7.599-62.072-8.038-61.793Q-8.478-61.514-9.031-61.514M-9.031-61.800Q-8.570-61.800-8.335-62.057Q-8.100-62.314-8.034-62.688Q-7.968-63.061-7.968-63.531L-7.968-63.566Q-7.968-64.054-8.025-64.419Q-8.082-64.784-8.311-65.047Q-8.539-65.311-8.983-65.311Q-9.352-65.311-9.603-65.067Q-9.853-64.823-9.968-64.459Q-10.082-64.094-10.082-63.747Q-10.082-63.628-10.073-63.566Q-10.073-63.549-10.075-63.538Q-10.077-63.527-10.082-63.514Q-10.082-62.863-9.844-62.332Q-9.607-61.800-9.031-61.800",[741],[730,2146],{"fill":732,"d":2147},"M-29.837-30.414c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.458-9.958 9.958 4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,2149,2151],{"transform":2150},"translate(-30.765 34.198)",[730,2152],{"d":2153,"fill":727,"stroke":727,"className":2154,"style":1272},"M-10.442-62.433L-10.486-62.433Q-10.284-62.116-9.897-61.958Q-9.510-61.800-9.084-61.800Q-8.548-61.800-8.309-62.235Q-8.069-62.670-8.069-63.250Q-8.069-63.830-8.315-64.270Q-8.561-64.709-9.093-64.709L-9.713-64.709Q-9.739-64.709-9.772-64.738Q-9.805-64.766-9.805-64.788L-9.805-64.889Q-9.805-64.920-9.776-64.944Q-9.748-64.968-9.713-64.968L-9.194-65.008Q-8.728-65.008-8.482-65.480Q-8.236-65.953-8.236-66.471Q-8.236-66.898-8.449-67.172Q-8.662-67.447-9.084-67.447Q-9.427-67.447-9.752-67.317Q-10.077-67.188-10.262-66.933L-10.236-66.933Q-10.033-66.933-9.897-66.792Q-9.761-66.651-9.761-66.454Q-9.761-66.256-9.895-66.122Q-10.029-65.988-10.227-65.988Q-10.429-65.988-10.567-66.122Q-10.706-66.256-10.706-66.454Q-10.706-67.043-10.203-67.374Q-9.699-67.706-9.084-67.706Q-8.706-67.706-8.304-67.566Q-7.902-67.425-7.634-67.146Q-7.366-66.867-7.366-66.471Q-7.366-65.922-7.720-65.485Q-8.073-65.047-8.614-64.863Q-8.223-64.784-7.878-64.560Q-7.533-64.336-7.322-63.995Q-7.111-63.654-7.111-63.259Q-7.111-62.877-7.274-62.554Q-7.436-62.231-7.728-61.995Q-8.021-61.760-8.368-61.637Q-8.715-61.514-9.084-61.514Q-9.532-61.514-9.963-61.675Q-10.394-61.835-10.675-62.162Q-10.956-62.490-10.956-62.947Q-10.956-63.162-10.809-63.305Q-10.662-63.448-10.442-63.448Q-10.231-63.448-10.086-63.303Q-9.941-63.158-9.941-62.947Q-9.941-62.736-10.088-62.584Q-10.236-62.433-10.442-62.433",[741],[730,2156],{"fill":732,"d":2157},"M-18.176-54.195-32.963-37.93M-45.486.884c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.459-9.958 9.958 4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,2159,2161],{"transform":2160},"translate(-46.414 65.496)",[730,2162],{"d":2163,"fill":727,"stroke":727,"className":2164,"style":1272},"M-7.436-61.712L-10.886-61.712L-10.886-61.945Q-10.886-61.958-10.855-61.989L-9.401-63.566Q-8.935-64.063-8.682-64.368Q-8.429-64.674-8.238-65.085Q-8.047-65.496-8.047-65.935Q-8.047-66.524-8.370-66.957Q-8.693-67.390-9.273-67.390Q-9.537-67.390-9.783-67.280Q-10.029-67.170-10.205-66.983Q-10.381-66.796-10.477-66.546L-10.398-66.546Q-10.196-66.546-10.053-66.410Q-9.910-66.274-9.910-66.058Q-9.910-65.852-10.053-65.713Q-10.196-65.575-10.398-65.575Q-10.600-65.575-10.743-65.718Q-10.886-65.860-10.886-66.058Q-10.886-66.520-10.649-66.893Q-10.411-67.267-10.011-67.486Q-9.612-67.706-9.163-67.706Q-8.640-67.706-8.186-67.491Q-7.731-67.275-7.458-66.876Q-7.186-66.476-7.186-65.935Q-7.186-65.540-7.357-65.186Q-7.529-64.832-7.794-64.553Q-8.060-64.274-8.511-63.889Q-8.961-63.505-9.040-63.430L-10.064-62.468L-9.247-62.468Q-8.596-62.468-8.159-62.479Q-7.722-62.490-7.691-62.512Q-7.621-62.595-7.566-62.835Q-7.511-63.074-7.471-63.342L-7.186-63.342",[741],[730,2166],{"fill":732,"d":2167},"m-44.339-21.328-6.563 13.127M-14.188.884c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.459-9.958 9.958 4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,2169,2171],{"transform":2170},"translate(-15.116 65.496)",[730,2172],{"d":2173,"fill":727,"stroke":727,"className":2174,"style":1272},"M-10.517-62.718Q-10.376-62.305-10.016-62.053Q-9.655-61.800-9.220-61.800Q-8.768-61.800-8.502-62.053Q-8.236-62.305-8.133-62.690Q-8.030-63.074-8.030-63.531Q-8.030-65.232-8.939-65.232Q-9.260-65.232-9.489-65.138Q-9.717-65.043-9.847-64.924Q-9.976-64.806-10.088-64.667Q-10.200-64.529-10.236-64.520L-10.319-64.520Q-10.363-64.520-10.394-64.551Q-10.425-64.582-10.425-64.630L-10.425-67.627Q-10.425-67.658-10.389-67.682Q-10.354-67.706-10.328-67.706L-10.288-67.706Q-9.655-67.416-8.983-67.416Q-8.311-67.416-7.669-67.706L-7.643-67.706Q-7.612-67.706-7.579-67.684Q-7.546-67.662-7.546-67.627L-7.546-67.526Q-7.546-67.522-7.555-67.504Q-7.564-67.486-7.564-67.482Q-7.880-67.087-8.350-66.865Q-8.821-66.643-9.317-66.643Q-9.726-66.643-10.108-66.753L-10.108-65.034Q-9.651-65.491-8.939-65.491Q-8.429-65.491-8.030-65.210Q-7.630-64.929-7.408-64.474Q-7.186-64.019-7.186-63.514Q-7.186-62.964-7.465-62.505Q-7.744-62.046-8.210-61.780Q-8.676-61.514-9.220-61.514Q-9.660-61.514-10.044-61.741Q-10.429-61.967-10.657-62.347Q-10.886-62.727-10.886-63.171Q-10.886-63.364-10.754-63.496Q-10.622-63.628-10.425-63.628Q-10.293-63.628-10.189-63.569Q-10.086-63.509-10.027-63.406Q-9.968-63.303-9.968-63.171Q-9.968-62.973-10.095-62.841Q-10.222-62.710-10.425-62.710Q-10.486-62.710-10.517-62.718",[741],[730,2176],{"fill":732,"d":2177},"m-35.253-21.328 6.564 13.127M27.068-30.414c0-5.5-4.458-9.958-9.958-9.958S7.15-35.914 7.15-30.414s4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2179,2181],{"transform":2180},"translate(26.14 34.198)",[730,2182],{"d":2183,"fill":727,"stroke":727,"className":2184,"style":1272},"M-10.956-63.079Q-10.956-63.637-10.596-64.050Q-10.236-64.463-9.660-64.735L-10.029-64.968Q-10.332-65.170-10.519-65.500Q-10.706-65.830-10.706-66.186Q-10.706-66.840-10.200-67.273Q-9.695-67.706-9.031-67.706Q-8.632-67.706-8.247-67.546Q-7.863-67.385-7.614-67.080Q-7.366-66.775-7.366-66.357Q-7.366-65.526-8.434-64.968L-7.880-64.621Q-7.533-64.393-7.322-64.024Q-7.111-63.654-7.111-63.241Q-7.111-62.863-7.269-62.545Q-7.427-62.226-7.704-61.993Q-7.981-61.760-8.324-61.637Q-8.667-61.514-9.031-61.514Q-9.497-61.514-9.943-61.701Q-10.389-61.888-10.673-62.242Q-10.956-62.595-10.956-63.079M-10.433-63.079Q-10.433-62.534-10.014-62.167Q-9.594-61.800-9.031-61.800Q-8.702-61.800-8.377-61.932Q-8.051-62.064-7.843-62.318Q-7.634-62.573-7.634-62.916Q-7.634-63.180-7.770-63.404Q-7.906-63.628-8.139-63.782L-9.383-64.564Q-9.844-64.327-10.139-63.940Q-10.433-63.553-10.433-63.079M-9.822-65.834L-8.706-65.131Q-8.482-65.254-8.278-65.443Q-8.073-65.632-7.953-65.865Q-7.832-66.098-7.832-66.357Q-7.832-66.665-8.003-66.915Q-8.175-67.166-8.451-67.306Q-8.728-67.447-9.040-67.447Q-9.489-67.447-9.862-67.201Q-10.236-66.955-10.236-66.528Q-10.236-66.124-9.822-65.834",[741],[730,2186],{"fill":732,"d":2187},"M-4.51-54.195 10.277-37.93M11.42.884c0-5.5-4.46-9.958-9.96-9.958S-8.497-4.615-8.497.884s4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.96 0",[725,2189,2191],{"transform":2190},"translate(10.491 65.496)",[730,2192],{"d":2193,"fill":727,"stroke":727,"className":2194,"style":1272},"M-9.721-61.954Q-9.721-62.591-9.565-63.237Q-9.409-63.883-9.117-64.489Q-8.825-65.096-8.416-65.645L-7.599-66.753L-8.627-66.753Q-10.271-66.753-10.319-66.709Q-10.425-66.581-10.543-65.878L-10.829-65.878L-10.534-67.794L-10.244-67.794L-10.244-67.768Q-10.244-67.605-9.680-67.557Q-9.115-67.508-8.570-67.508L-6.852-67.508L-6.852-67.302Q-6.852-67.284-6.854-67.275Q-6.856-67.267-6.861-67.258L-8.148-65.509Q-8.399-65.157-8.546-64.731Q-8.693-64.305-8.759-63.841Q-8.825-63.378-8.838-62.967Q-8.851-62.556-8.851-61.954Q-8.851-61.774-8.977-61.644Q-9.102-61.514-9.282-61.514Q-9.401-61.514-9.504-61.571Q-9.607-61.629-9.664-61.732Q-9.721-61.835-9.721-61.954",[741],[730,2196],{"fill":732,"d":2197},"M12.567-21.328 6.003-8.201M42.717.884c0-5.5-4.458-9.958-9.958-9.958S22.8-4.615 22.8.884s4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2199,2201],{"transform":2200},"translate(41.79 65.496)",[730,2202],{"d":2203,"fill":727,"stroke":727,"className":2204,"style":1272},"M-10.280-62.099Q-10.033-61.800-9.427-61.800Q-9.146-61.800-8.906-61.938Q-8.667-62.077-8.489-62.299Q-8.311-62.521-8.201-62.784Q-7.968-63.360-7.968-64.476Q-8.135-64.111-8.440-63.887Q-8.746-63.663-9.128-63.663Q-9.664-63.663-10.080-63.942Q-10.495-64.221-10.726-64.687Q-10.956-65.153-10.956-65.680Q-10.956-66.093-10.809-66.462Q-10.662-66.832-10.398-67.108Q-10.135-67.385-9.765-67.546Q-9.396-67.706-8.983-67.706Q-8.425-67.706-8.051-67.414Q-7.678-67.122-7.474-66.658Q-7.269-66.194-7.190-65.678Q-7.111-65.162-7.111-64.630Q-7.111-63.914-7.379-63.191Q-7.647-62.468-8.170-61.991Q-8.693-61.514-9.418-61.514Q-9.968-61.514-10.345-61.763Q-10.723-62.011-10.723-62.529Q-10.723-62.648-10.666-62.751Q-10.609-62.855-10.508-62.914Q-10.407-62.973-10.280-62.973Q-10.095-62.973-9.972-62.841Q-9.849-62.710-9.849-62.529Q-9.849-62.354-9.976-62.226Q-10.104-62.099-10.280-62.099M-9.084-63.927Q-8.715-63.927-8.467-64.169Q-8.218-64.410-8.102-64.768Q-7.986-65.127-7.986-65.500Q-7.986-65.610-7.994-65.663Q-7.990-65.676-7.988-65.687Q-7.986-65.698-7.986-65.715Q-7.986-66.370-8.201-66.909Q-8.416-67.447-8.983-67.447Q-9.343-67.447-9.572-67.297Q-9.801-67.148-9.917-66.891Q-10.033-66.634-10.066-66.353Q-10.099-66.071-10.099-65.698L-10.099-65.663Q-10.099-65.337-10.073-65.050Q-10.047-64.762-9.948-64.503Q-9.849-64.243-9.638-64.085Q-9.427-63.927-9.084-63.927",[741],[730,2206],{"fill":732,"d":2207},"m21.652-21.328 6.564 13.127",[725,2209,2210],{"stroke":1395,"style":1339},[730,2211],{"fill":732,"d":2138},[725,2213,2214],{"stroke":1395,"style":1339},[730,2215],{"fill":732,"d":2216},"M11.42.884c0-5.5-4.46-9.958-9.96-9.958S-8.497-4.615-8.497.884s4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.96 0",[725,2218,2219,2222],{"fill":1338,"stroke":1338,"style":1409},[730,2220],{"fill":732,"d":2221},"M-3.309-55.496C3.572-50.172 7.04-46.358 10.297-41.2",[730,2223],{"stroke":732,"d":2224},"m11.686-39.002-.463-4.628-.926 2.43-2.591-.209",[725,2226,2227,2230],{"fill":1338,"stroke":1338,"style":1409},[730,2228],{"fill":732,"d":2229},"M14.214-20.677c-1.673 5.622-3.208 8.692-5.153 11.315",[730,2231],{"stroke":732,"d":2232},"m7.512-7.274 4.148-2.102-2.6.014-.74-2.492",[730,2234],{"fill":732,"d":2235},"M180.713-61.712c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.458-9.958 9.958 4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,2237,2239],{"transform":2238},"translate(179.785 2.9)",[730,2240],{"d":2143,"fill":727,"stroke":727,"className":2241,"style":1272},[741],[730,2243],{"fill":732,"d":2244},"M152.26-30.414c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.458-9.959 9.958 4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2246,2248],{"transform":2247},"translate(151.332 34.198)",[730,2249],{"d":2153,"fill":727,"stroke":727,"className":2250,"style":1272},[741],[730,2252],{"fill":732,"d":2253},"M163.921-54.195 149.134-37.93M136.611.884c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.459-9.959 9.958 4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2255,2257],{"transform":2256},"translate(135.683 65.496)",[730,2258],{"d":2163,"fill":727,"stroke":727,"className":2259,"style":1272},[741],[730,2261],{"fill":732,"d":2262},"m137.759-21.328-6.564 13.127M167.909.884c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.459-9.959 9.958 4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2264,2266],{"transform":2265},"translate(166.981 65.496)",[730,2267],{"d":2173,"fill":727,"stroke":727,"className":2268,"style":1272},[741],[730,2270],{"fill":732,"d":2271},"m146.844-21.328 6.564 13.127M209.165-30.414c0-5.5-4.458-9.958-9.958-9.958s-9.958 4.458-9.958 9.958 4.458 9.959 9.958 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2273,2275],{"transform":2274},"translate(208.238 34.198)",[730,2276],{"d":2183,"fill":727,"stroke":727,"className":2277,"style":1272},[741],[730,2279],{"fill":732,"d":2280},"m177.587-54.195 14.787 16.265M193.517.884c0-5.5-4.459-9.958-9.959-9.958S173.6-4.615 173.6.884s4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,2282,2284],{"transform":2283},"translate(192.589 65.496)",[730,2285],{"d":2193,"fill":727,"stroke":727,"className":2286,"style":1272},[741],[730,2288],{"fill":732,"d":2289},"m194.664-21.328-6.563 13.127M224.815.884c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.459-9.958 9.958 4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,2291,2293],{"transform":2292},"translate(223.887 65.496)",[730,2294],{"d":2203,"fill":727,"stroke":727,"className":2295,"style":1272},[741],[730,2297],{"fill":732,"d":2298},"m203.75-21.328 6.563 13.127",[725,2300,2301],{"stroke":1395,"style":1339},[730,2302],{"fill":732,"d":2303},"M167.909.884c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.459-9.959 9.958 4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,2305,2306],{"stroke":1395,"style":1339},[730,2307],{"fill":732,"d":2235},[725,2309,2310,2313],{"fill":1338,"stroke":1338,"style":1409},[730,2311],{"fill":732,"d":2312},"M151.345-6.832c-3.89-4.544-5.532-7.83-6.268-11.13",[730,2314],{"stroke":732,"d":2315},"m144.511-20.499-1.125 4.513 1.69-1.975 2.37 1.07",[725,2317,2318,2321],{"fill":1338,"stroke":1338,"style":1409},[730,2319],{"fill":732,"d":2320},"M147.113-39.36c4.176-7.763 7.862-11.817 13.03-15.268",[730,2322],{"stroke":732,"d":2323},"m162.306-56.072-4.615.58 2.453.864-.143 2.596",[807,2325,2327,2328,2343,2344,2359,2360,2375,2376,2391,2392,2444,2445,443],{"className":2326},[810],"The two successor cases. Left: ",[390,2329,2331],{"className":2330},[393],[390,2332,2334],{"className":2333,"ariaHidden":398},[397],[390,2335,2337,2340],{"className":2336},[402],[390,2338],{"className":2339,"style":827},[406],[390,2341,831],{"className":2342},[411]," has a right subtree, so its successor is that subtree's minimum, ",[390,2345,2347],{"className":2346},[393],[390,2348,2350],{"className":2349,"ariaHidden":398},[397],[390,2351,2353,2356],{"className":2352},[402],[390,2354],{"className":2355,"style":827},[406],[390,2357,937],{"className":2358},[411]," (descend left from ",[390,2361,2363],{"className":2362},[393],[390,2364,2366],{"className":2365,"ariaHidden":398},[397],[390,2367,2369,2372],{"className":2368},[402],[390,2370],{"className":2371,"style":827},[406],[390,2373,947],{"className":2374},[411],"). Right: ",[390,2377,2379],{"className":2378},[393],[390,2380,2382],{"className":2381,"ariaHidden":398},[397],[390,2383,2385,2388],{"className":2384},[402],[390,2386],{"className":2387,"style":827},[406],[390,2389,881],{"className":2390},[411]," has no right subtree, so climb until moving up a left link — ",[390,2393,2395],{"className":2394},[393],[390,2396,2398,2417,2435],{"className":2397,"ariaHidden":398},[397],[390,2399,2401,2404,2407,2410,2414],{"className":2400},[402],[390,2402],{"className":2403,"style":827},[406],[390,2405,881],{"className":2406},[411],[390,2408],{"className":2409,"style":569},[568],[390,2411,2413],{"className":2412},[573],"→",[390,2415],{"className":2416,"style":569},[568],[390,2418,2420,2423,2426,2429,2432],{"className":2419},[402],[390,2421],{"className":2422,"style":827},[406],[390,2424,871],{"className":2425},[411],[390,2427],{"className":2428,"style":569},[568],[390,2430,2413],{"className":2431},[573],[390,2433],{"className":2434,"style":569},[568],[390,2436,2438,2441],{"className":2437},[402],[390,2439],{"className":2440,"style":827},[406],[390,2442,831],{"className":2443},[411]," — giving successor ",[390,2446,2448],{"className":2447},[393],[390,2449,2451],{"className":2450,"ariaHidden":398},[397],[390,2452,2454,2457],{"className":2453},[402],[390,2455],{"className":2456,"style":827},[406],[390,2458,831],{"className":2459},[411],[445,2461,2463],{"id":2462},"deleting-a-node","Deleting a node",[381,2465,2466],{},"Deletion is the one operation that needs care, because removing an internal node\nleaves a hole that must be filled without disturbing the BST property. There are\nthree cases, in increasing difficulty:",[2468,2469,2470,2494,2531],"ol",{},[1939,2471,2472,2489,2490,2493],{},[390,2473,2475],{"className":2474},[393],[390,2476,2478],{"className":2477,"ariaHidden":398},[397],[390,2479,2481,2484],{"className":2480},[402],[390,2482],{"className":2483,"style":464},[406],[390,2485,2488],{"className":2486,"style":2487},[411,412],"margin-right:0.044em;","z"," has ",[431,2491,2492],{},"no children",": just detach it from its parent.",[1939,2495,2496,2489,2511,2514,2515,2530],{},[390,2497,2499],{"className":2498},[393],[390,2500,2502],{"className":2501,"ariaHidden":398},[397],[390,2503,2505,2508],{"className":2504},[402],[390,2506],{"className":2507,"style":464},[406],[390,2509,2488],{"className":2510,"style":2487},[411,412],[431,2512,2513],{},"one child",": splice that child into ",[390,2516,2518],{"className":2517},[393],[390,2519,2521],{"className":2520,"ariaHidden":398},[397],[390,2522,2524,2527],{"className":2523},[402],[390,2525],{"className":2526,"style":464},[406],[390,2528,2488],{"className":2529,"style":2487},[411,412],"'s position.",[1939,2532,2533,2489,2548,2551,2552,2567,2568,2583,2584,2599,2600,2615,2616,2631,2632,2647,2648,2663,2664,2679],{},[390,2534,2536],{"className":2535},[393],[390,2537,2539],{"className":2538,"ariaHidden":398},[397],[390,2540,2542,2545],{"className":2541},[402],[390,2543],{"className":2544,"style":464},[406],[390,2546,2488],{"className":2547,"style":2487},[411,412],[431,2549,2550],{},"two children",": ",[390,2553,2555],{"className":2554},[393],[390,2556,2558],{"className":2557,"ariaHidden":398},[397],[390,2559,2561,2564],{"className":2560},[402],[390,2562],{"className":2563,"style":464},[406],[390,2565,2488],{"className":2566,"style":2487},[411,412],"'s successor ",[390,2569,2571],{"className":2570},[393],[390,2572,2574],{"className":2573,"ariaHidden":398},[397],[390,2575,2577,2580],{"className":2576},[402],[390,2578],{"className":2579,"style":508},[406],[390,2581,513],{"className":2582,"style":512},[411,412]," is the minimum of its right\nsubtree, so ",[390,2585,2587],{"className":2586},[393],[390,2588,2590],{"className":2589,"ariaHidden":398},[397],[390,2591,2593,2596],{"className":2592},[402],[390,2594],{"className":2595,"style":508},[406],[390,2597,513],{"className":2598,"style":512},[411,412]," has no left child. Move ",[390,2601,2603],{"className":2602},[393],[390,2604,2606],{"className":2605,"ariaHidden":398},[397],[390,2607,2609,2612],{"className":2608},[402],[390,2610],{"className":2611,"style":508},[406],[390,2613,513],{"className":2614,"style":512},[411,412]," into ",[390,2617,2619],{"className":2618},[393],[390,2620,2622],{"className":2621,"ariaHidden":398},[397],[390,2623,2625,2628],{"className":2624},[402],[390,2626],{"className":2627,"style":464},[406],[390,2629,2488],{"className":2630,"style":2487},[411,412],"'s position; if ",[390,2633,2635],{"className":2634},[393],[390,2636,2638],{"className":2637,"ariaHidden":398},[397],[390,2639,2641,2644],{"className":2640},[402],[390,2642],{"className":2643,"style":508},[406],[390,2645,513],{"className":2646,"style":512},[411,412]," was\nnot ",[390,2649,2651],{"className":2650},[393],[390,2652,2654],{"className":2653,"ariaHidden":398},[397],[390,2655,2657,2660],{"className":2656},[402],[390,2658],{"className":2659,"style":464},[406],[390,2661,2488],{"className":2662,"style":2487},[411,412],"'s direct child, first replace ",[390,2665,2667],{"className":2666},[393],[390,2668,2670],{"className":2669,"ariaHidden":398},[397],[390,2671,2673,2676],{"className":2672},[402],[390,2674],{"className":2675,"style":508},[406],[390,2677,513],{"className":2678,"style":512},[411,412]," by its own right child.",[381,2681,2682,2683,2706,2707,2723,2724,469],{},"All three reduce to a single primitive, ",[390,2684,2686],{"className":2685},[393],[390,2687,2689],{"className":2688,"ariaHidden":398},[397],[390,2690,2692,2696],{"className":2691},[402],[390,2693],{"className":2694,"style":2695},[406],"height:0.8889em;vertical-align:-0.1944em;",[390,2697,2699],{"className":2698},[1630,1631],[390,2700,2702],{"className":2701},[411,1635],[390,2703,2705],{"className":2704},[411],"Transplant",", which replaces the\nsubtree rooted at ",[390,2708,2710],{"className":2709},[393],[390,2711,2713],{"className":2712,"ariaHidden":398},[397],[390,2714,2716,2719],{"className":2715},[402],[390,2717],{"className":2718,"style":464},[406],[390,2720,2722],{"className":2721},[411,412],"u"," with the subtree rooted at ",[390,2725,2727],{"className":2726},[393],[390,2728,2730],{"className":2729,"ariaHidden":398},[397],[390,2731,2733,2736],{"className":2732},[402],[390,2734],{"className":2735,"style":464},[406],[390,2737,2739],{"className":2738,"style":512},[411,412],"v",[1076,2741,2743],{"className":1078,"code":2742,"language":1080,"meta":376,"style":376},"caption: $\\textsc{Transplant}(T, u, v)$ — put subtree $v$ where subtree $u$ was\nif $parent(u) = \\text{nil}$ then\n  $root(T) \\gets v$\nelse if $u = left(parent(u))$ then\n  $left(parent(u)) \\gets v$\nelse\n  $right(parent(u)) \\gets v$\nif $v \\ne \\text{nil}$ then\n  $parent(v) \\gets parent(u)$\n",[1082,2744,2745,2750,2755,2760,2765,2770,2774,2779,2784],{"__ignoreMap":376},[390,2746,2747],{"class":1086,"line":6},[390,2748,2749],{},"caption: $\\textsc{Transplant}(T, u, v)$ — put subtree $v$ where subtree $u$ was\n",[390,2751,2752],{"class":1086,"line":18},[390,2753,2754],{},"if $parent(u) = \\text{nil}$ then\n",[390,2756,2757],{"class":1086,"line":24},[390,2758,2759],{},"  $root(T) \\gets v$\n",[390,2761,2762],{"class":1086,"line":73},[390,2763,2764],{},"else if $u = left(parent(u))$ then\n",[390,2766,2767],{"class":1086,"line":102},[390,2768,2769],{},"  $left(parent(u)) \\gets v$\n",[390,2771,2772],{"class":1086,"line":108},[390,2773,1114],{},[390,2775,2776],{"class":1086,"line":116},[390,2777,2778],{},"  $right(parent(u)) \\gets v$\n",[390,2780,2781],{"class":1086,"line":196},[390,2782,2783],{},"if $v \\ne \\text{nil}$ then\n",[390,2785,2786],{"class":1086,"line":202},[390,2787,2788],{},"  $parent(v) \\gets parent(u)$\n",[1076,2790,2792],{"className":1078,"code":2791,"language":1080,"meta":376,"style":376},"caption: $\\textsc{Tree-Delete}(T, z)$ — remove node $z$ from the BST\nif $left(z) = \\text{nil}$ then\n  call $\\textsc{Transplant}(T, z, right(z))$ \u002F\u002F lift the right child\nelse if $right(z) = \\text{nil}$ then\n  call $\\textsc{Transplant}(T, z, left(z))$ \u002F\u002F lift the left child\nelse\n  $y \\gets$ call $\\textsc{Tree-Minimum}(right(z))$ \u002F\u002F successor, no left child\n  if $parent(y) \\ne z$ then\n    call $\\textsc{Transplant}(T, y, right(y))$ \u002F\u002F detach y, lift its right child\n    $right(y) \\gets right(z)$\n    $parent(right(y)) \\gets y$\n  call $\\textsc{Transplant}(T, z, y)$ \u002F\u002F y into z's slot\n  $left(y) \\gets left(z)$\n  $parent(left(y)) \\gets y$\n",[1082,2793,2794,2799,2804,2809,2814,2819,2823,2828,2833,2838,2843,2848,2853,2858],{"__ignoreMap":376},[390,2795,2796],{"class":1086,"line":6},[390,2797,2798],{},"caption: $\\textsc{Tree-Delete}(T, z)$ — remove node $z$ from the BST\n",[390,2800,2801],{"class":1086,"line":18},[390,2802,2803],{},"if $left(z) = \\text{nil}$ then\n",[390,2805,2806],{"class":1086,"line":24},[390,2807,2808],{},"  call $\\textsc{Transplant}(T, z, right(z))$ \u002F\u002F lift the right child\n",[390,2810,2811],{"class":1086,"line":73},[390,2812,2813],{},"else if $right(z) = \\text{nil}$ then\n",[390,2815,2816],{"class":1086,"line":102},[390,2817,2818],{},"  call $\\textsc{Transplant}(T, z, left(z))$ \u002F\u002F lift the left child\n",[390,2820,2821],{"class":1086,"line":108},[390,2822,1114],{},[390,2824,2825],{"class":1086,"line":116},[390,2826,2827],{},"  $y \\gets$ call $\\textsc{Tree-Minimum}(right(z))$ \u002F\u002F successor, no left child\n",[390,2829,2830],{"class":1086,"line":196},[390,2831,2832],{},"  if $parent(y) \\ne z$ then\n",[390,2834,2835],{"class":1086,"line":202},[390,2836,2837],{},"    call $\\textsc{Transplant}(T, y, right(y))$ \u002F\u002F detach y, lift its right child\n",[390,2839,2840],{"class":1086,"line":283},[390,2841,2842],{},"    $right(y) \\gets right(z)$\n",[390,2844,2845],{"class":1086,"line":333},[390,2846,2847],{},"    $parent(right(y)) \\gets y$\n",[390,2849,2850],{"class":1086,"line":354},[390,2851,2852],{},"  call $\\textsc{Transplant}(T, z, y)$ \u002F\u002F y into z's slot\n",[390,2854,2855],{"class":1086,"line":1827},[390,2856,2857],{},"  $left(y) \\gets left(z)$\n",[390,2859,2860],{"class":1086,"line":1833},[390,2861,2862],{},"  $parent(left(y)) \\gets y$\n",[381,2864,2865,2866,2881,2882,2897],{},"The two-child case is the subtle one. Replacing ",[390,2867,2869],{"className":2868},[393],[390,2870,2872],{"className":2871,"ariaHidden":398},[397],[390,2873,2875,2878],{"className":2874},[402],[390,2876],{"className":2877,"style":464},[406],[390,2879,2488],{"className":2880,"style":2487},[411,412]," by its successor keeps every\nkey in ",[390,2883,2885],{"className":2884},[393],[390,2886,2888],{"className":2887,"ariaHidden":398},[397],[390,2889,2891,2894],{"className":2890},[402],[390,2892],{"className":2893,"style":464},[406],[390,2895,2488],{"className":2896,"style":2487},[411,412],"'s left subtree below the new root and every key in the right subtree\nabove it, so the ordering survives:",[712,2899,2901,3086],{"className":2900},[715,716],[718,2902,2906],{"xmlns":720,"width":2903,"height":2904,"viewBox":2905},"434.729","167.869","-75 -75 326.046 125.901",[725,2907,2908,2920,2923,2929,2932,2938,2941,2948,2951,2958,2971,2974,2981,2984,2991,2994,3010,3018,3029,3032,3038,3041,3047,3050,3056,3059,3065,3068,3074,3077,3083],{"stroke":727,"style":728},[725,2909,2911,2914],{"fill":2910},"var(--tk-soft-warn)",[730,2912],{"d":2913},"M8.574-62.112c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.458-9.958 9.958 4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,2915,2916],{"transform":1267},[730,2917],{"d":2918,"fill":727,"stroke":727,"className":2919,"style":1272},"M-0.559-63.118Q-0.418-62.705-0.058-62.453Q0.303-62.200 0.738-62.200Q1.190-62.200 1.456-62.453Q1.722-62.705 1.825-63.090Q1.928-63.474 1.928-63.931Q1.928-65.632 1.019-65.632Q0.698-65.632 0.469-65.538Q0.241-65.443 0.111-65.324Q-0.018-65.206-0.130-65.067Q-0.242-64.929-0.278-64.920L-0.361-64.920Q-0.405-64.920-0.436-64.951Q-0.467-64.982-0.467-65.030L-0.467-68.027Q-0.467-68.058-0.431-68.082Q-0.396-68.106-0.370-68.106L-0.330-68.106Q0.303-67.816 0.975-67.816Q1.647-67.816 2.289-68.106L2.315-68.106Q2.346-68.106 2.379-68.084Q2.412-68.062 2.412-68.027L2.412-67.926Q2.412-67.922 2.403-67.904Q2.394-67.886 2.394-67.882Q2.078-67.487 1.608-67.265Q1.137-67.043 0.641-67.043Q0.232-67.043-0.150-67.153L-0.150-65.434Q0.307-65.891 1.019-65.891Q1.529-65.891 1.928-65.610Q2.328-65.329 2.550-64.874Q2.772-64.419 2.772-63.914Q2.772-63.364 2.493-62.905Q2.214-62.446 1.748-62.180Q1.282-61.914 0.738-61.914Q0.298-61.914-0.086-62.141Q-0.471-62.367-0.699-62.747Q-0.928-63.127-0.928-63.571Q-0.928-63.764-0.796-63.896Q-0.664-64.028-0.467-64.028Q-0.335-64.028-0.231-63.969Q-0.128-63.909-0.069-63.806Q-0.010-63.703-0.010-63.571Q-0.010-63.373-0.137-63.241Q-0.264-63.110-0.467-63.110Q-0.528-63.110-0.559-63.118",[741],[730,2921],{"fill":732,"d":2922},"M-28.415-27.968c0-5.5-4.459-9.959-9.959-9.959s-9.958 4.459-9.958 9.959 4.459 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,2924,2925],{"transform":1278},[730,2926],{"d":2927,"fill":727,"stroke":727,"className":2928,"style":1272},"M-0.484-62.833L-0.528-62.833Q-0.326-62.516 0.061-62.358Q0.448-62.200 0.874-62.200Q1.410-62.200 1.649-62.635Q1.889-63.070 1.889-63.650Q1.889-64.230 1.643-64.670Q1.397-65.109 0.865-65.109L0.245-65.109Q0.219-65.109 0.186-65.138Q0.153-65.166 0.153-65.188L0.153-65.289Q0.153-65.320 0.182-65.344Q0.210-65.368 0.245-65.368L0.764-65.408Q1.230-65.408 1.476-65.880Q1.722-66.353 1.722-66.871Q1.722-67.298 1.509-67.572Q1.296-67.847 0.874-67.847Q0.531-67.847 0.206-67.717Q-0.119-67.588-0.304-67.333L-0.278-67.333Q-0.075-67.333 0.061-67.192Q0.197-67.051 0.197-66.854Q0.197-66.656 0.063-66.522Q-0.071-66.388-0.269-66.388Q-0.471-66.388-0.609-66.522Q-0.748-66.656-0.748-66.854Q-0.748-67.443-0.245-67.774Q0.259-68.106 0.874-68.106Q1.252-68.106 1.654-67.966Q2.056-67.825 2.324-67.546Q2.592-67.267 2.592-66.871Q2.592-66.322 2.238-65.885Q1.885-65.447 1.344-65.263Q1.735-65.184 2.080-64.960Q2.425-64.736 2.636-64.395Q2.847-64.054 2.847-63.659Q2.847-63.277 2.684-62.954Q2.522-62.631 2.230-62.395Q1.937-62.160 1.590-62.037Q1.243-61.914 0.874-61.914Q0.426-61.914-0.005-62.075Q-0.436-62.235-0.717-62.562Q-0.998-62.890-0.998-63.347Q-0.998-63.562-0.851-63.705Q-0.704-63.848-0.484-63.848Q-0.273-63.848-0.128-63.703Q0.017-63.558 0.017-63.347Q0.017-63.136-0.130-62.984Q-0.278-62.833-0.484-62.833",[741],[730,2930],{"fill":732,"d":2931},"M45.562-27.968c0-5.5-4.458-9.959-9.958-9.959s-9.959 4.459-9.959 9.959 4.459 9.958 9.959 9.958 9.958-4.458 9.958-9.958Zm-9.958 0",[725,2933,2934],{"transform":1308},[730,2935],{"d":2936,"fill":727,"stroke":727,"className":2937,"style":1272},"M-0.998-63.479Q-0.998-64.037-0.638-64.450Q-0.278-64.863 0.298-65.135L-0.071-65.368Q-0.374-65.570-0.561-65.900Q-0.748-66.230-0.748-66.586Q-0.748-67.240-0.242-67.673Q0.263-68.106 0.927-68.106Q1.326-68.106 1.711-67.946Q2.095-67.785 2.344-67.480Q2.592-67.174 2.592-66.757Q2.592-65.926 1.524-65.368L2.078-65.021Q2.425-64.793 2.636-64.424Q2.847-64.054 2.847-63.641Q2.847-63.263 2.689-62.945Q2.531-62.626 2.254-62.393Q1.977-62.160 1.634-62.037Q1.291-61.914 0.927-61.914Q0.461-61.914 0.015-62.101Q-0.431-62.288-0.715-62.642Q-0.998-62.995-0.998-63.479M-0.475-63.479Q-0.475-62.934-0.056-62.567Q0.364-62.200 0.927-62.200Q1.256-62.200 1.581-62.332Q1.907-62.464 2.115-62.718Q2.324-62.973 2.324-63.316Q2.324-63.580 2.188-63.804Q2.052-64.028 1.819-64.182L0.575-64.964Q0.114-64.727-0.181-64.340Q-0.475-63.953-0.475-63.479M0.136-66.234L1.252-65.531Q1.476-65.654 1.680-65.843Q1.885-66.032 2.005-66.265Q2.126-66.498 2.126-66.757Q2.126-67.065 1.955-67.315Q1.783-67.566 1.507-67.706Q1.230-67.847 0.918-67.847Q0.469-67.847 0.096-67.601Q-0.278-67.355-0.278-66.928Q-0.278-66.524 0.136-66.234",[741],[730,2939],{"fill":732,"d":2940},"M-45.486 6.175c0-5.5-4.459-9.959-9.959-9.959s-9.958 4.459-9.958 9.959 4.458 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,2942,2944],{"transform":2943},"translate(-56.373 71.186)",[730,2945],{"d":2946,"fill":727,"stroke":727,"className":2947,"style":1272},"M2.522-62.112L-0.928-62.112L-0.928-62.345Q-0.928-62.358-0.897-62.389L0.557-63.966Q1.023-64.463 1.276-64.768Q1.529-65.074 1.720-65.485Q1.911-65.896 1.911-66.335Q1.911-66.924 1.588-67.357Q1.265-67.790 0.685-67.790Q0.421-67.790 0.175-67.680Q-0.071-67.570-0.247-67.383Q-0.423-67.196-0.519-66.946L-0.440-66.946Q-0.238-66.946-0.095-66.810Q0.048-66.674 0.048-66.458Q0.048-66.252-0.095-66.113Q-0.238-65.975-0.440-65.975Q-0.642-65.975-0.785-66.118Q-0.928-66.260-0.928-66.458Q-0.928-66.920-0.691-67.293Q-0.453-67.667-0.053-67.886Q0.346-68.106 0.795-68.106Q1.318-68.106 1.772-67.891Q2.227-67.675 2.500-67.276Q2.772-66.876 2.772-66.335Q2.772-65.940 2.601-65.586Q2.429-65.232 2.164-64.953Q1.898-64.674 1.447-64.289Q0.997-63.905 0.918-63.830L-0.106-62.868L0.711-62.868Q1.362-62.868 1.799-62.879Q2.236-62.890 2.267-62.912Q2.337-62.995 2.392-63.235Q2.447-63.474 2.487-63.742L2.772-63.742",[741],[730,2949],{"fill":732,"d":2950},"M-11.343 6.175c0-5.5-4.459-9.959-9.959-9.959S-31.26.675-31.26 6.175s4.458 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,2952,2954],{"transform":2953},"translate(-22.23 71.186)",[730,2955],{"d":2956,"fill":727,"stroke":727,"className":2957,"style":1272},"M1.313-63.589L-1.126-63.589L-1.126-63.905L1.700-68.053Q1.744-68.106 1.810-68.106L1.964-68.106Q2.003-68.106 2.036-68.073Q2.069-68.040 2.069-67.996L2.069-63.905L2.970-63.905L2.970-63.589L2.069-63.589L2.069-62.723Q2.069-62.428 2.970-62.428L2.970-62.112L0.417-62.112L0.417-62.428Q0.777-62.428 1.045-62.483Q1.313-62.538 1.313-62.723L1.313-63.589M1.370-67.078L-0.792-63.905L1.370-63.905",[741],[725,2959,2961,2964],{"fill":2960},"var(--tk-soft-accent)",[730,2962],{"d":2963},"M28.49 6.175c0-5.5-4.458-9.959-9.958-9.959S8.573.675 8.573 6.175s4.459 9.958 9.959 9.958 9.958-4.458 9.958-9.958Zm-9.958 0",[725,2965,2967],{"transform":2966},"translate(17.604 71.186)",[730,2968],{"d":2969,"fill":727,"stroke":727,"className":2970,"style":1272},"M0.927-61.914Q0.193-61.914-0.238-62.395Q-0.669-62.877-0.833-63.569Q-0.998-64.261-0.998-65.008Q-0.998-65.737-0.706-66.460Q-0.414-67.183 0.140-67.645Q0.694-68.106 1.441-68.106Q1.937-68.106 2.273-67.840Q2.610-67.574 2.610-67.091Q2.610-66.911 2.482-66.783Q2.355-66.656 2.179-66.656Q1.999-66.656 1.869-66.781Q1.740-66.906 1.740-67.091Q1.740-67.205 1.797-67.309Q1.854-67.412 1.955-67.471Q2.056-67.530 2.179-67.530Q2.183-67.530 2.188-67.528Q2.192-67.526 2.197-67.522Q2.082-67.689 1.874-67.768Q1.665-67.847 1.441-67.847Q0.997-67.847 0.639-67.546Q0.281-67.245 0.092-66.792Q-0.141-66.186-0.141-65.153Q0.030-65.518 0.331-65.746Q0.632-65.975 1.019-65.975Q1.423-65.975 1.768-65.808Q2.113-65.641 2.350-65.360Q2.588-65.078 2.717-64.716Q2.847-64.353 2.847-63.949Q2.847-63.404 2.603-62.938Q2.359-62.472 1.920-62.193Q1.480-61.914 0.927-61.914M0.927-62.200Q1.388-62.200 1.623-62.457Q1.858-62.714 1.924-63.088Q1.990-63.461 1.990-63.931L1.990-63.966Q1.990-64.454 1.933-64.819Q1.876-65.184 1.647-65.447Q1.419-65.711 0.975-65.711Q0.606-65.711 0.355-65.467Q0.105-65.223-0.010-64.859Q-0.124-64.494-0.124-64.147Q-0.124-64.028-0.115-63.966Q-0.115-63.949-0.117-63.938Q-0.119-63.927-0.124-63.914Q-0.124-63.263 0.114-62.732Q0.351-62.200 0.927-62.200",[741],[730,2972],{"fill":732,"d":2973},"M62.634 6.175c0-5.5-4.459-9.959-9.959-9.959S42.717.675 42.717 6.175s4.458 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,2975,2977],{"transform":2976},"translate(51.748 71.186)",[730,2978],{"d":2979,"fill":727,"stroke":727,"className":2980,"style":1272},"M-0.322-62.499Q-0.075-62.200 0.531-62.200Q0.812-62.200 1.052-62.338Q1.291-62.477 1.469-62.699Q1.647-62.921 1.757-63.184Q1.990-63.760 1.990-64.876Q1.823-64.511 1.518-64.287Q1.212-64.063 0.830-64.063Q0.294-64.063-0.122-64.342Q-0.537-64.621-0.768-65.087Q-0.998-65.553-0.998-66.080Q-0.998-66.493-0.851-66.862Q-0.704-67.232-0.440-67.508Q-0.177-67.785 0.193-67.946Q0.562-68.106 0.975-68.106Q1.533-68.106 1.907-67.814Q2.280-67.522 2.484-67.058Q2.689-66.594 2.768-66.078Q2.847-65.562 2.847-65.030Q2.847-64.314 2.579-63.591Q2.311-62.868 1.788-62.391Q1.265-61.914 0.540-61.914Q-0.010-61.914-0.387-62.163Q-0.765-62.411-0.765-62.929Q-0.765-63.048-0.708-63.151Q-0.651-63.255-0.550-63.314Q-0.449-63.373-0.322-63.373Q-0.137-63.373-0.014-63.241Q0.109-63.110 0.109-62.929Q0.109-62.754-0.018-62.626Q-0.146-62.499-0.322-62.499M0.874-64.327Q1.243-64.327 1.491-64.569Q1.740-64.810 1.856-65.168Q1.972-65.527 1.972-65.900Q1.972-66.010 1.964-66.063Q1.968-66.076 1.970-66.087Q1.972-66.098 1.972-66.115Q1.972-66.770 1.757-67.309Q1.542-67.847 0.975-67.847Q0.615-67.847 0.386-67.697Q0.157-67.548 0.041-67.291Q-0.075-67.034-0.108-66.753Q-0.141-66.471-0.141-66.098L-0.141-66.063Q-0.141-65.737-0.115-65.450Q-0.089-65.162 0.010-64.903Q0.109-64.643 0.320-64.485Q0.531-64.327 0.874-64.327",[741],[730,2982],{"fill":732,"d":2983},"M39.872 37.473c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.458-9.958 9.958 4.458 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,2985,2987],{"transform":2986},"translate(28.986 102.485)",[730,2988],{"d":2989,"fill":727,"stroke":727,"className":2990,"style":1272},"M0.237-62.354Q0.237-62.991 0.393-63.637Q0.549-64.283 0.841-64.889Q1.133-65.496 1.542-66.045L2.359-67.153L1.331-67.153Q-0.313-67.153-0.361-67.109Q-0.467-66.981-0.585-66.278L-0.871-66.278L-0.576-68.194L-0.286-68.194L-0.286-68.168Q-0.286-68.005 0.278-67.957Q0.843-67.908 1.388-67.908L3.106-67.908L3.106-67.702Q3.106-67.684 3.104-67.675Q3.102-67.667 3.097-67.658L1.810-65.909Q1.559-65.557 1.412-65.131Q1.265-64.705 1.199-64.241Q1.133-63.778 1.120-63.367Q1.107-62.956 1.107-62.354Q1.107-62.174 0.981-62.044Q0.856-61.914 0.676-61.914Q0.557-61.914 0.454-61.971Q0.351-62.029 0.294-62.132Q0.237-62.235 0.237-62.354",[741],[730,2992],{"fill":732,"d":2993},"m-8.849-55.222-22.06 20.364M6.08-55.222l22.06 20.364M-42.916-18.883-50.902-2.91M-33.83-18.883l7.986 15.973M31.06-18.883 23.076-2.91M40.146-18.883 48.133-2.91M22.004 15.722l4.438 12.204",[725,2995,2997,3004],{"stroke":732,"fontFamily":2996,"fontSize":937},"cmr7",[725,2998,3000],{"transform":2999},"translate(80.318 46.532)",[730,3001],{"d":3002,"fill":727,"stroke":727,"className":3003,"style":1354},"M-1.071-63.623Q-1.071-63.961-0.930-64.252Q-0.790-64.542-0.546-64.756Q-0.302-64.969 0.003-65.084Q0.307-65.198 0.632-65.198Q0.902-65.198 1.165-65.099Q1.428-65 1.619-64.822L1.619-66.220Q1.619-66.490 1.512-66.552Q1.404-66.613 1.093-66.613L1.093-66.894L2.170-66.969L2.170-62.785Q2.170-62.597 2.224-62.514Q2.279-62.430 2.380-62.411Q2.481-62.392 2.696-62.392L2.696-62.112L1.589-62.044L1.589-62.461Q1.172-62.044 0.546-62.044Q0.115-62.044-0.257-62.256Q-0.630-62.467-0.850-62.828Q-1.071-63.189-1.071-63.623M0.604-62.266Q0.813-62.266 0.999-62.338Q1.185-62.409 1.339-62.546Q1.493-62.683 1.589-62.861L1.589-64.470Q1.503-64.617 1.358-64.737Q1.213-64.857 1.043-64.916Q0.874-64.976 0.693-64.976Q0.133-64.976-0.136-64.587Q-0.404-64.197-0.404-63.616Q-0.404-63.045-0.170-62.655Q0.064-62.266 0.604-62.266M3.304-63.647Q3.304-63.968 3.429-64.257Q3.554-64.546 3.780-64.769Q4.005-64.993 4.301-65.113Q4.596-65.233 4.914-65.233Q5.242-65.233 5.504-65.133Q5.765-65.034 5.941-64.852Q6.117-64.669 6.211-64.411Q6.305-64.153 6.305-63.821Q6.305-63.729 6.223-63.708L3.968-63.708L3.968-63.647Q3.968-63.059 4.251-62.676Q4.535-62.293 5.102-62.293Q5.424-62.293 5.692-62.486Q5.960-62.679 6.049-62.994Q6.056-63.035 6.131-63.049L6.223-63.049Q6.305-63.025 6.305-62.953Q6.305-62.946 6.299-62.919Q6.186-62.522 5.815-62.283Q5.444-62.044 5.020-62.044Q4.583-62.044 4.183-62.252Q3.783-62.461 3.544-62.828Q3.304-63.195 3.304-63.647M3.974-63.917L5.789-63.917Q5.789-64.194 5.692-64.446Q5.594-64.699 5.396-64.855Q5.198-65.010 4.914-65.010Q4.637-65.010 4.424-64.852Q4.210-64.693 4.092-64.438Q3.974-64.183 3.974-63.917M8.561-62.112L6.958-62.112L6.958-62.392Q7.184-62.392 7.333-62.426Q7.481-62.461 7.481-62.601L7.481-66.220Q7.481-66.490 7.374-66.552Q7.266-66.613 6.958-66.613L6.958-66.894L8.035-66.969L8.035-62.601Q8.035-62.464 8.185-62.428Q8.336-62.392 8.561-62.392L8.561-62.112M9.115-63.647Q9.115-63.968 9.240-64.257Q9.365-64.546 9.590-64.769Q9.816-64.993 10.111-65.113Q10.407-65.233 10.725-65.233Q11.053-65.233 11.314-65.133Q11.576-65.034 11.752-64.852Q11.928-64.669 12.022-64.411Q12.116-64.153 12.116-63.821Q12.116-63.729 12.034-63.708L9.778-63.708L9.778-63.647Q9.778-63.059 10.062-62.676Q10.345-62.293 10.913-62.293Q11.234-62.293 11.502-62.486Q11.771-62.679 11.860-62.994Q11.866-63.035 11.942-63.049L12.034-63.049Q12.116-63.025 12.116-62.953Q12.116-62.946 12.109-62.919Q11.996-62.522 11.625-62.283Q11.255-62.044 10.831-62.044Q10.393-62.044 9.993-62.252Q9.594-62.461 9.354-62.828Q9.115-63.195 9.115-63.647M9.785-63.917L11.600-63.917Q11.600-64.194 11.502-64.446Q11.405-64.699 11.207-64.855Q11.009-65.010 10.725-65.010Q10.448-65.010 10.234-64.852Q10.021-64.693 9.903-64.438Q9.785-64.183 9.785-63.917M13.230-62.953L13.230-64.850L12.591-64.850L12.591-65.072Q12.909-65.072 13.126-65.282Q13.343-65.492 13.444-65.802Q13.545-66.111 13.545-66.419L13.811-66.419L13.811-65.130L14.888-65.130L14.888-64.850L13.811-64.850L13.811-62.966Q13.811-62.690 13.916-62.491Q14.020-62.293 14.280-62.293Q14.437-62.293 14.543-62.397Q14.649-62.502 14.698-62.655Q14.748-62.809 14.748-62.966L14.748-63.380L15.014-63.380L15.014-62.953Q15.014-62.727 14.915-62.517Q14.816-62.307 14.632-62.175Q14.447-62.044 14.218-62.044Q13.781-62.044 13.505-62.281Q13.230-62.519 13.230-62.953M15.783-63.647Q15.783-63.968 15.908-64.257Q16.033-64.546 16.259-64.769Q16.484-64.993 16.780-65.113Q17.075-65.233 17.393-65.233Q17.721-65.233 17.983-65.133Q18.244-65.034 18.420-64.852Q18.596-64.669 18.690-64.411Q18.784-64.153 18.784-63.821Q18.784-63.729 18.702-63.708L16.447-63.708L16.447-63.647Q16.447-63.059 16.730-62.676Q17.014-62.293 17.581-62.293Q17.903-62.293 18.171-62.486Q18.439-62.679 18.528-62.994Q18.535-63.035 18.610-63.049L18.702-63.049Q18.784-63.025 18.784-62.953Q18.784-62.946 18.778-62.919Q18.665-62.522 18.294-62.283Q17.923-62.044 17.499-62.044Q17.062-62.044 16.662-62.252Q16.262-62.461 16.023-62.828Q15.783-63.195 15.783-63.647M16.453-63.917L18.268-63.917Q18.268-64.194 18.171-64.446Q18.073-64.699 17.875-64.855Q17.677-65.010 17.393-65.010Q17.116-65.010 16.903-64.852Q16.689-64.693 16.571-64.438Q16.453-64.183 16.453-63.917",[741],[725,3005,3006],{"transform":2999},[730,3007],{"d":3008,"fill":727,"stroke":727,"className":3009,"style":1354},"M22.589-62.874L22.558-62.874Q22.695-62.577 22.992-62.401Q23.289-62.225 23.617-62.225Q23.980-62.225 24.207-62.403Q24.434-62.580 24.528-62.869Q24.622-63.158 24.622-63.520Q24.622-63.835 24.568-64.120Q24.513-64.405 24.340-64.611Q24.168-64.816 23.853-64.816Q23.580-64.816 23.397-64.749Q23.214-64.682 23.110-64.593Q23.006-64.505 22.910-64.395Q22.814-64.286 22.770-64.276L22.691-64.276Q22.619-64.293 22.602-64.364L22.602-66.682Q22.602-66.716 22.626-66.738Q22.650-66.760 22.684-66.760L22.712-66.760Q22.999-66.644 23.267-66.590Q23.535-66.535 23.812-66.535Q24.089-66.535 24.359-66.590Q24.629-66.644 24.909-66.760L24.933-66.760Q24.968-66.760 24.991-66.737Q25.015-66.713 25.015-66.682L25.015-66.613Q25.015-66.586 24.995-66.566Q24.721-66.251 24.337-66.075Q23.952-65.899 23.539-65.899Q23.200-65.899 22.883-65.985L22.883-64.703Q23.279-65.038 23.853-65.038Q24.257-65.038 24.593-64.828Q24.930-64.617 25.123-64.265Q25.316-63.913 25.316-63.513Q25.316-63.182 25.176-62.896Q25.036-62.611 24.792-62.401Q24.547-62.191 24.245-62.081Q23.942-61.972 23.624-61.972Q23.265-61.972 22.939-62.136Q22.613-62.300 22.418-62.592Q22.223-62.884 22.223-63.247Q22.223-63.397 22.329-63.503Q22.435-63.609 22.589-63.609Q22.742-63.609 22.847-63.505Q22.951-63.401 22.951-63.247Q22.951-63.090 22.847-62.982Q22.742-62.874 22.589-62.874",[741],[725,3011,3012,3015],{"style":1409},[730,3013],{"fill":732,"d":3014},"M69.747-8.052h37.234",[730,3016],{"stroke":732,"d":3017},"m109.58-8.052-4.16-2.08 1.56 2.08-1.56 2.08",[725,3019,3020,3023],{"fill":2960},[730,3021],{"d":3022},"M193.516-62.112c0-5.5-4.458-9.958-9.958-9.958s-9.958 4.458-9.958 9.958 4.458 9.959 9.958 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,3024,3026],{"transform":3025},"translate(182.63 2.9)",[730,3027],{"d":2969,"fill":727,"stroke":727,"className":3028,"style":1272},[741],[730,3030],{"fill":732,"d":3031},"M156.528-27.968c0-5.5-4.459-9.959-9.959-9.959s-9.958 4.459-9.958 9.959 4.458 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,3033,3035],{"transform":3034},"translate(145.642 37.043)",[730,3036],{"d":2927,"fill":727,"stroke":727,"className":3037,"style":1272},[741],[730,3039],{"fill":732,"d":3040},"M230.505-27.968c0-5.5-4.458-9.959-9.958-9.959s-9.959 4.459-9.959 9.959 4.459 9.958 9.959 9.958 9.958-4.458 9.958-9.958Zm-9.958 0",[725,3042,3044],{"transform":3043},"translate(219.619 37.043)",[730,3045],{"d":2936,"fill":727,"stroke":727,"className":3046,"style":1272},[741],[730,3048],{"fill":732,"d":3049},"M139.456 6.175c0-5.5-4.458-9.959-9.958-9.959s-9.959 4.459-9.959 9.959 4.459 9.958 9.959 9.958 9.958-4.458 9.958-9.958Zm-9.958 0",[725,3051,3053],{"transform":3052},"translate(128.57 71.186)",[730,3054],{"d":2946,"fill":727,"stroke":727,"className":3055,"style":1272},[741],[730,3057],{"fill":732,"d":3058},"M173.6 6.175c0-5.5-4.459-9.959-9.959-9.959s-9.958 4.459-9.958 9.959 4.458 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,3060,3062],{"transform":3061},"translate(162.714 71.186)",[730,3063],{"d":2956,"fill":727,"stroke":727,"className":3064,"style":1272},[741],[730,3066],{"fill":732,"d":3067},"M213.433 6.175c0-5.5-4.458-9.959-9.958-9.959s-9.959 4.459-9.959 9.959 4.459 9.958 9.959 9.958 9.958-4.458 9.958-9.958Zm-9.958 0",[725,3069,3071],{"transform":3070},"translate(202.547 71.186)",[730,3072],{"d":2989,"fill":727,"stroke":727,"className":3073,"style":1272},[741],[730,3075],{"fill":732,"d":3076},"M247.576 6.175c0-5.5-4.458-9.959-9.958-9.959S227.66.675 227.66 6.175s4.458 9.958 9.958 9.958 9.958-4.458 9.958-9.958Zm-9.958 0",[725,3078,3080],{"transform":3079},"translate(236.69 71.186)",[730,3081],{"d":2979,"fill":727,"stroke":727,"className":3082,"style":1272},[741],[730,3084],{"fill":732,"d":3085},"m176.094-55.222-22.06 20.364M191.022-55.222l22.06 20.364M142.027-18.883 134.04-2.91M151.112-18.883 159.1-2.91M216.004-18.883 208.017-2.91M225.09-18.883l7.985 15.973",[807,3087,3089,3090,3105,3106,3121],{"className":3088},[810],"Deleting a node with two children: its successor (the minimum of the right subtree, here ",[390,3091,3093],{"className":3092},[393],[390,3094,3096],{"className":3095,"ariaHidden":398},[397],[390,3097,3099,3102],{"className":3098},[402],[390,3100],{"className":3101,"style":827},[406],[390,3103,831],{"className":3104},[411],") takes its place, and the successor's own right child (",[390,3107,3109],{"className":3108},[393],[390,3110,3112],{"className":3111,"ariaHidden":398},[397],[390,3113,3115,3118],{"className":3114},[402],[390,3116],{"className":3117,"style":827},[406],[390,3119,937],{"className":3120},[411],") fills the slot it vacated.",[381,3123,3124,3125,3146,3147,3169,3170,3194],{},"Each branch does a constant amount of pointer surgery plus at most one\n",[390,3126,3128],{"className":3127},[393],[390,3129,3131],{"className":3130,"ariaHidden":398},[397],[390,3132,3134,3137],{"className":3133},[402],[390,3135],{"className":3136,"style":1626},[406],[390,3138,3140],{"className":3139},[1630,1631],[390,3141,3143],{"className":3142},[411,1635],[390,3144,1639],{"className":3145},[411]," call, so ",[390,3148,3150],{"className":3149},[393],[390,3151,3153],{"className":3152,"ariaHidden":398},[397],[390,3154,3156,3159],{"className":3155},[402],[390,3157],{"className":3158,"style":1038},[406],[390,3160,3162],{"className":3161},[1630,1631],[390,3163,3165],{"className":3164},[411,1635],[390,3166,3168],{"className":3167},[411],"Tree-Delete"," runs in ",[390,3171,3173],{"className":3172},[393],[390,3174,3176],{"className":3175,"ariaHidden":398},[397],[390,3177,3179,3182,3185,3188,3191],{"className":3178},[402],[390,3180],{"className":3181,"style":407},[406],[390,3183,414],{"className":3184,"style":413},[411,412],[390,3186,419],{"className":3187},[418],[390,3189,1224],{"className":3190},[411,412],[390,3192,428],{"className":3193},[427]," like the rest.",[445,3196,3198],{"id":3197},"the-order-is-already-there-inorder-walk","The order is already there: inorder walk",[381,3200,3201,3202,3205,3206],{},"Because the BST property sorts keys left-to-right at every node, visiting the\ntree ",[431,3203,3204],{},"in order"," — left subtree, then the node, then right subtree — emits the\nkeys in increasing order.",[702,3207,3208],{},[385,3209,871],{"href":3210,"ariaDescribedBy":3211,"dataFootnoteRef":376,"id":3212},"#user-content-fn-erickson-bst",[708],"user-content-fnref-erickson-bst",[1076,3214,3216],{"className":1078,"code":3215,"language":1080,"meta":376,"style":376},"caption: $\\textsc{Inorder-Walk}(x)$ — print the subtree at $x$ in sorted order\nif $x \\ne \\text{nil}$ then\n  call $\\textsc{Inorder-Walk}(left(x))$ \u002F\u002F smaller keys first\n  print $key(x)$\n  call $\\textsc{Inorder-Walk}(right(x))$ \u002F\u002F then larger keys\n",[1082,3217,3218,3223,3228,3233,3238],{"__ignoreMap":376},[390,3219,3220],{"class":1086,"line":6},[390,3221,3222],{},"caption: $\\textsc{Inorder-Walk}(x)$ — print the subtree at $x$ in sorted order\n",[390,3224,3225],{"class":1086,"line":18},[390,3226,3227],{},"if $x \\ne \\text{nil}$ then\n",[390,3229,3230],{"class":1086,"line":24},[390,3231,3232],{},"  call $\\textsc{Inorder-Walk}(left(x))$ \u002F\u002F smaller keys first\n",[390,3234,3235],{"class":1086,"line":73},[390,3236,3237],{},"  print $key(x)$\n",[390,3239,3240],{"class":1086,"line":102},[390,3241,3242],{},"  call $\\textsc{Inorder-Walk}(right(x))$ \u002F\u002F then larger keys\n",[471,3244,3245],{"type":473},[381,3246,3247,3250,3251,3273],{},[431,3248,3249],{},"Claim."," ",[390,3252,3254],{"className":3253},[393],[390,3255,3257],{"className":3256,"ariaHidden":398},[397],[390,3258,3260,3263],{"className":3259},[402],[390,3261],{"className":3262,"style":1038},[406],[390,3264,3266],{"className":3265},[1630,1631],[390,3267,3269],{"className":3268},[411,1635],[390,3270,3272],{"className":3271},[411],"Inorder-Walk"," on a BST prints the keys in nondecreasing order.",[471,3275,3277],{"type":3276},"proof",[381,3278,3279,3282,3283,3299,3300,3315,3316,3332,3333,3372,3373,3412,3413,3440,3441,3479,3480,3519,3520],{},[431,3280,3281],{},"Proof by induction on subtree size."," A subtree of size ",[390,3284,3286],{"className":3285},[393],[390,3287,3289],{"className":3288,"ariaHidden":398},[397],[390,3290,3292,3295],{"className":3291},[402],[390,3293],{"className":3294,"style":827},[406],[390,3296,3298],{"className":3297},[411],"0"," prints nothing,\nvacuously sorted. For a subtree rooted at ",[390,3301,3303],{"className":3302},[393],[390,3304,3306],{"className":3305,"ariaHidden":398},[397],[390,3307,3309,3312],{"className":3308},[402],[390,3310],{"className":3311,"style":464},[406],[390,3313,468],{"className":3314},[411,412]," of size ",[390,3317,3319],{"className":3318},[393],[390,3320,3322],{"className":3321,"ariaHidden":398},[397],[390,3323,3325,3328],{"className":3324},[402],[390,3326],{"className":3327,"style":464},[406],[390,3329,3331],{"className":3330},[411,412],"n",", the recursive call on\n",[390,3334,3336],{"className":3335},[393],[390,3337,3339],{"className":3338,"ariaHidden":398},[397],[390,3340,3342,3345,3350,3354,3359,3363,3366,3369],{"className":3341},[402],[390,3343],{"className":3344,"style":407},[406],[390,3346,3349],{"className":3347,"style":3348},[411,412],"margin-right:0.0197em;","l",[390,3351,3353],{"className":3352},[411,412],"e",[390,3355,3358],{"className":3356,"style":3357},[411,412],"margin-right:0.1076em;","f",[390,3360,3362],{"className":3361},[411,412],"t",[390,3364,419],{"className":3365},[418],[390,3367,468],{"className":3368},[411,412],[390,3370,428],{"className":3371},[427]," prints, by the induction hypothesis, all keys ",[390,3374,3376],{"className":3375},[393],[390,3377,3379,3391],{"className":3378,"ariaHidden":398},[397],[390,3380,3382,3385,3388],{"className":3381},[402],[390,3383],{"className":3384,"style":899},[406],[390,3386,574],{"className":3387},[573],[390,3389],{"className":3390,"style":569},[568],[390,3392,3394,3397,3400,3403,3406,3409],{"className":3393},[402],[390,3395],{"className":3396,"style":407},[406],[390,3398,551],{"className":3399,"style":550},[411,412],[390,3401,555],{"className":3402,"style":512},[411,412],[390,3404,419],{"className":3405},[418],[390,3407,468],{"className":3408},[411,412],[390,3410,428],{"className":3411},[427]," in sorted\norder; we then print ",[390,3414,3416],{"className":3415},[393],[390,3417,3419],{"className":3418,"ariaHidden":398},[397],[390,3420,3422,3425,3428,3431,3434,3437],{"className":3421},[402],[390,3423],{"className":3424,"style":407},[406],[390,3426,551],{"className":3427,"style":550},[411,412],[390,3429,555],{"className":3430,"style":512},[411,412],[390,3432,419],{"className":3433},[418],[390,3435,468],{"className":3436},[411,412],[390,3438,428],{"className":3439},[427],"; then the recursive call on ",[390,3442,3444],{"className":3443},[393],[390,3445,3447],{"className":3446,"ariaHidden":398},[397],[390,3448,3450,3453,3457,3461,3464,3467,3470,3473,3476],{"className":3449},[402],[390,3451],{"className":3452,"style":407},[406],[390,3454,3456],{"className":3455,"style":413},[411,412],"r",[390,3458,3460],{"className":3459},[411,412],"i",[390,3462,725],{"className":3463,"style":512},[411,412],[390,3465,1224],{"className":3466},[411,412],[390,3468,3362],{"className":3469},[411,412],[390,3471,419],{"className":3472},[418],[390,3474,468],{"className":3475},[411,412],[390,3477,428],{"className":3478},[427]," prints all\nkeys ",[390,3481,3483],{"className":3482},[393],[390,3484,3486,3498],{"className":3485,"ariaHidden":398},[397],[390,3487,3489,3492,3495],{"className":3488},[402],[390,3490],{"className":3491,"style":899},[406],[390,3493,669],{"className":3494},[573],[390,3496],{"className":3497,"style":569},[568],[390,3499,3501,3504,3507,3510,3513,3516],{"className":3500},[402],[390,3502],{"className":3503,"style":407},[406],[390,3505,551],{"className":3506,"style":550},[411,412],[390,3508,555],{"className":3509,"style":512},[411,412],[390,3511,419],{"className":3512},[418],[390,3514,468],{"className":3515},[411,412],[390,3517,428],{"className":3518},[427]," in sorted order. Concatenated, the output is sorted. ",[390,3521,3523],{"className":3522},[393],[390,3524,3526],{"className":3525,"ariaHidden":398},[397],[390,3527,3529,3533],{"className":3528},[402],[390,3530],{"className":3531,"style":3532},[406],"height:0.675em;",[390,3534,3537],{"className":3535},[1630,3536],"qed",[390,3538,3541],{"className":3539},[411,3540],"amsrm","□",[381,3543,3544,3545,3560,3561,3586],{},"The walk visits each of ",[390,3546,3548],{"className":3547},[393],[390,3549,3551],{"className":3550,"ariaHidden":398},[397],[390,3552,3554,3557],{"className":3553},[402],[390,3555],{"className":3556,"style":464},[406],[390,3558,3331],{"className":3559},[411,412]," nodes once, so it runs in ",[390,3562,3564],{"className":3563},[393],[390,3565,3567],{"className":3566,"ariaHidden":398},[397],[390,3568,3570,3573,3577,3580,3583],{"className":3569},[402],[390,3571],{"className":3572,"style":407},[406],[390,3574,3576],{"className":3575},[411],"Θ",[390,3578,419],{"className":3579},[418],[390,3581,3331],{"className":3582},[411,412],[390,3584,428],{"className":3585},[427]," time. This\ngives a clean way to read out a sorted sequence, and shows that a BST is, in\neffect, a dynamic sorted list you can also splice into and search.",[445,3588,3590],{"id":3589},"the-catch-height-is-everything","The catch: height is everything",[381,3592,3593,3594,3618,3619,3634,3635,3638,3639,3642,3643,3698,3699,443],{},"Every operation above costs ",[390,3595,3597],{"className":3596},[393],[390,3598,3600],{"className":3599,"ariaHidden":398},[397],[390,3601,3603,3606,3609,3612,3615],{"className":3602},[402],[390,3604],{"className":3605,"style":407},[406],[390,3607,414],{"className":3608,"style":413},[411,412],[390,3610,419],{"className":3611},[418],[390,3613,1224],{"className":3614},[411,412],[390,3616,428],{"className":3617},[427],". So the BST is fast exactly when ",[390,3620,3622],{"className":3621},[393],[390,3623,3625],{"className":3624,"ariaHidden":398},[397],[390,3626,3628,3631],{"className":3627},[402],[390,3629],{"className":3630,"style":1038},[406],[390,3632,1224],{"className":3633},[411,412]," is\nsmall. The ",[431,3636,3637],{},"best case"," is a ",[436,3640,3641],{},"balanced"," tree, where the two subtrees of each\nnode have nearly equal size; then ",[390,3644,3646],{"className":3645},[393],[390,3647,3649,3667],{"className":3648,"ariaHidden":398},[397],[390,3650,3652,3655,3658,3661,3664],{"className":3651},[402],[390,3653],{"className":3654,"style":1038},[406],[390,3656,1224],{"className":3657},[411,412],[390,3659],{"className":3660,"style":569},[568],[390,3662,1449],{"className":3663},[573],[390,3665],{"className":3666,"style":569},[568],[390,3668,3670,3673,3676,3679,3689,3692,3695],{"className":3669},[402],[390,3671],{"className":3672,"style":407},[406],[390,3674,3576],{"className":3675},[411],[390,3677,419],{"className":3678},[418],[390,3680,3683],{"className":3681},[3682],"mop",[390,3684,3688],{"className":3685,"style":3687},[411,3686],"mathrm","margin-right:0.0139em;","log",[390,3690],{"className":3691,"style":867},[568],[390,3693,3331],{"className":3694},[411,412],[390,3696,428],{"className":3697},[427]," and every operation is\n",[390,3700,3702],{"className":3701},[393],[390,3703,3705],{"className":3704,"ariaHidden":398},[397],[390,3706,3708,3711,3714,3717,3723,3726,3729],{"className":3707},[402],[390,3709],{"className":3710,"style":407},[406],[390,3712,3576],{"className":3713},[411],[390,3715,419],{"className":3716},[418],[390,3718,3720],{"className":3719},[3682],[390,3721,3688],{"className":3722,"style":3687},[411,3686],[390,3724],{"className":3725,"style":867},[568],[390,3727,3331],{"className":3728},[411,412],[390,3730,428],{"className":3731},[427],[381,3733,1886,3734,3737,3738,3741,3742,3798],{},[431,3735,3736],{},"worst case"," is a disaster. Suppose we insert keys in ",[436,3739,3740],{},"sorted"," order:\n",[390,3743,3745],{"className":3744},[393],[390,3746,3748],{"className":3747,"ariaHidden":398},[397],[390,3749,3751,3755,3758,3761,3764,3767,3770,3773,3776,3779,3782,3786,3789,3792,3795],{"className":3750},[402],[390,3752],{"className":3753,"style":3754},[406],"height:0.8389em;vertical-align:-0.1944em;",[390,3756,423],{"className":3757},[411],[390,3759,863],{"className":3760},[862],[390,3762],{"className":3763,"style":867},[568],[390,3765,858],{"className":3766},[411],[390,3768,863],{"className":3769},[862],[390,3771],{"className":3772,"style":867},[568],[390,3774,871],{"className":3775},[411],[390,3777,863],{"className":3778},[862],[390,3780],{"className":3781,"style":867},[568],[390,3783,3785],{"className":3784},[848],"…",[390,3787],{"className":3788,"style":867},[568],[390,3790,863],{"className":3791},[862],[390,3793],{"className":3794,"style":867},[568],[390,3796,3331],{"className":3797},[411,412],". Each new key is larger than everything present, so it walks\nall the way right and attaches as the rightmost leaf. The tree degenerates into a\nsingle descending path, a glorified linked list:",[712,3800,3802,3861],{"className":3801},[715,716],[718,3803,3807],{"xmlns":720,"width":3804,"height":3805,"viewBox":3806},"115.408","171.662","-75 -75 86.556 128.747",[725,3808,3809,3812,3818,3821,3828,3831,3838,3841,3848,3851,3858],{"stroke":727,"style":728},[730,3810],{"fill":732,"d":3811},"M-48.82-62.112c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.458-9.959 9.958 4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,3813,3814],{"transform":736},[730,3815],{"d":3816,"fill":727,"stroke":727,"className":3817,"style":742},"M-54.569-62.112L-57.850-62.112L-57.850-62.464Q-56.600-62.464-56.600-62.781L-56.600-68.030Q-57.118-67.781-57.909-67.781L-57.909-68.133Q-56.683-68.133-56.058-68.772L-55.917-68.772Q-55.882-68.772-55.851-68.745Q-55.819-68.718-55.819-68.684L-55.819-62.781Q-55.819-62.464-54.569-62.464",[741],[730,3819],{"fill":732,"d":3820},"M-34.593-36.504c0-5.5-4.459-9.959-9.959-9.959s-9.958 4.459-9.958 9.959 4.458 9.958 9.958 9.958 9.959-4.458 9.959-9.958Zm-9.959 0",[725,3822,3824],{"transform":3823},"translate(11.726 28.83)",[730,3825],{"d":3826,"fill":727,"stroke":727,"className":3827,"style":742},"M-54.569-62.112L-58.280-62.112L-58.280-62.381Q-58.280-62.405-58.260-62.434L-56.708-64.153Q-56.356-64.534-56.136-64.793Q-55.917-65.051-55.702-65.388Q-55.487-65.725-55.362-66.074Q-55.238-66.424-55.238-66.814Q-55.238-67.224-55.389-67.598Q-55.541-67.971-55.841-68.196Q-56.141-68.421-56.566-68.421Q-57.001-68.421-57.347-68.159Q-57.694-67.898-57.836-67.483Q-57.797-67.493-57.728-67.493Q-57.504-67.493-57.345-67.341Q-57.186-67.190-57.186-66.951Q-57.186-66.721-57.345-66.563Q-57.504-66.404-57.728-66.404Q-57.963-66.404-58.121-66.568Q-58.280-66.731-58.280-66.951Q-58.280-67.327-58.138-67.656Q-57.997-67.986-57.731-68.242Q-57.465-68.499-57.130-68.635Q-56.796-68.772-56.420-68.772Q-55.848-68.772-55.355-68.530Q-54.862-68.289-54.574-67.847Q-54.286-67.405-54.286-66.814Q-54.286-66.380-54.476-65.989Q-54.667-65.598-54.965-65.279Q-55.262-64.959-55.726-64.553Q-56.190-64.148-56.337-64.011L-57.469-62.923L-56.507-62.923Q-55.799-62.923-55.323-62.935Q-54.847-62.947-54.818-62.971Q-54.701-63.098-54.579-63.894L-54.286-63.894",[741],[730,3829],{"fill":732,"d":3830},"m-53.845-53.232 4.36 7.848M-20.367-10.897c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.458-9.959 9.958 4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[725,3832,3834],{"transform":3833},"translate(25.953 54.437)",[730,3835],{"d":3836,"fill":727,"stroke":727,"className":3837,"style":742},"M-57.777-62.883L-57.826-62.883Q-57.591-62.542-57.196-62.376Q-56.800-62.210-56.346-62.210Q-55.765-62.210-55.521-62.705Q-55.277-63.201-55.277-63.831Q-55.277-64.114-55.328-64.397Q-55.380-64.680-55.502-64.924Q-55.624-65.169-55.836-65.315Q-56.049-65.462-56.356-65.462L-57.020-65.462Q-57.108-65.462-57.108-65.554L-57.108-65.642Q-57.108-65.720-57.020-65.720L-56.468-65.764Q-56.117-65.764-55.885-66.028Q-55.653-66.292-55.546-66.670Q-55.438-67.049-55.438-67.390Q-55.438-67.869-55.663-68.176Q-55.887-68.484-56.346-68.484Q-56.727-68.484-57.074-68.340Q-57.421-68.196-57.626-67.903Q-57.606-67.908-57.591-67.910Q-57.577-67.913-57.557-67.913Q-57.333-67.913-57.181-67.757Q-57.030-67.600-57.030-67.381Q-57.030-67.166-57.181-67.009Q-57.333-66.853-57.557-66.853Q-57.777-66.853-57.933-67.009Q-58.090-67.166-58.090-67.381Q-58.090-67.810-57.831-68.128Q-57.572-68.445-57.164-68.609Q-56.757-68.772-56.346-68.772Q-56.044-68.772-55.707-68.682Q-55.370-68.591-55.096-68.423Q-54.823-68.255-54.650-67.991Q-54.476-67.727-54.476-67.390Q-54.476-66.970-54.664-66.614Q-54.852-66.258-55.179-65.999Q-55.507-65.740-55.897-65.613Q-55.463-65.530-55.072-65.286Q-54.681-65.042-54.445-64.661Q-54.208-64.280-54.208-63.841Q-54.208-63.289-54.510-62.842Q-54.813-62.395-55.306-62.144Q-55.799-61.892-56.346-61.892Q-56.815-61.892-57.286-62.070Q-57.757-62.249-58.058-62.605Q-58.358-62.962-58.358-63.460Q-58.358-63.709-58.192-63.875Q-58.026-64.041-57.777-64.041Q-57.616-64.041-57.482-63.965Q-57.347-63.889-57.272-63.753Q-57.196-63.616-57.196-63.460Q-57.196-63.216-57.367-63.050Q-57.538-62.883-57.777-62.883",[741],[730,3839],{"fill":732,"d":3840},"m-39.618-27.624 4.36 7.847M-6.14 14.71c0-5.5-4.46-9.958-9.959-9.958-5.5 0-9.958 4.459-9.958 9.959s4.458 9.958 9.958 9.958 9.958-4.458 9.958-9.958Zm-9.959 0",[725,3842,3844],{"transform":3843},"translate(40.18 80.045)",[730,3845],{"d":3846,"fill":727,"stroke":727,"className":3847,"style":742},"M-55.858-63.762L-58.500-63.762L-58.500-64.114L-55.409-68.723Q-55.375-68.772-55.306-68.772L-55.160-68.772Q-55.048-68.772-55.048-68.660L-55.048-64.114L-54.066-64.114L-54.066-63.762L-55.048-63.762L-55.048-62.781Q-55.048-62.576-54.755-62.520Q-54.462-62.464-54.076-62.464L-54.076-62.112L-56.830-62.112L-56.830-62.464Q-56.444-62.464-56.151-62.520Q-55.858-62.576-55.858-62.781L-55.858-63.762M-55.799-67.654L-58.168-64.114L-55.799-64.114",[741],[730,3849],{"fill":732,"d":3850},"m-25.392-2.017 4.36 7.848M8.086 40.318c0-5.5-4.459-9.958-9.959-9.958s-9.958 4.458-9.958 9.958 4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959Zm-9.959 0",[725,3852,3854],{"transform":3853},"translate(54.406 105.652)",[730,3855],{"d":3856,"fill":727,"stroke":727,"className":3857,"style":742},"M-57.909-63.250Q-57.806-62.957-57.594-62.717Q-57.382-62.478-57.091-62.344Q-56.800-62.210-56.488-62.210Q-55.765-62.210-55.492-62.771Q-55.218-63.333-55.218-64.133Q-55.218-64.480-55.231-64.717Q-55.243-64.954-55.297-65.174Q-55.389-65.525-55.621-65.789Q-55.853-66.052-56.190-66.052Q-56.527-66.052-56.769-65.950Q-57.010-65.847-57.162-65.711Q-57.313-65.574-57.430-65.423Q-57.548-65.271-57.577-65.261L-57.689-65.261Q-57.714-65.261-57.750-65.293Q-57.787-65.325-57.787-65.354L-57.787-68.694Q-57.787-68.718-57.755-68.745Q-57.723-68.772-57.689-68.772L-57.660-68.772Q-56.986-68.450-56.229-68.450Q-55.487-68.450-54.799-68.772L-54.769-68.772Q-54.735-68.772-54.706-68.748Q-54.676-68.723-54.676-68.694L-54.676-68.601Q-54.676-68.552-54.696-68.552Q-55.038-68.098-55.553-67.844Q-56.068-67.591-56.620-67.591Q-57.020-67.591-57.440-67.703L-57.440-65.813Q-57.108-66.082-56.847-66.196Q-56.586-66.311-56.180-66.311Q-55.629-66.311-55.192-65.994Q-54.755-65.676-54.520-65.166Q-54.286-64.656-54.286-64.124Q-54.286-63.523-54.581-63.010Q-54.877-62.498-55.384-62.195Q-55.892-61.892-56.488-61.892Q-56.981-61.892-57.394-62.146Q-57.806-62.400-58.043-62.830Q-58.280-63.259-58.280-63.743Q-58.280-63.967-58.133-64.109Q-57.987-64.251-57.767-64.251Q-57.548-64.251-57.399-64.107Q-57.250-63.963-57.250-63.743Q-57.250-63.528-57.399-63.379Q-57.548-63.230-57.767-63.230Q-57.801-63.230-57.845-63.237Q-57.889-63.245-57.909-63.250",[741],[730,3859],{"fill":732,"d":3860},"m-11.166 23.59 4.36 7.848",[807,3862,3864,3865],{"className":3863},[810],"Sorted insertions degenerate a BST into a path of height ",[390,3866,3868],{"className":3867},[393],[390,3869,3871,3893],{"className":3870,"ariaHidden":398},[397],[390,3872,3874,3878,3881,3885,3890],{"className":3873},[402],[390,3875],{"className":3876,"style":3877},[406],"height:0.6667em;vertical-align:-0.0833em;",[390,3879,3331],{"className":3880},[411,412],[390,3882],{"className":3883,"style":3884},[568],"margin-right:0.2222em;",[390,3886,3889],{"className":3887},[3888],"mbin","−",[390,3891],{"className":3892,"style":3884},[568],[390,3894,3896,3899],{"className":3895},[402],[390,3897],{"className":3898,"style":827},[406],[390,3900,423],{"className":3901},[411],[381,3903,3904,3905,3956,3957,3981,3982,3990],{},"Now ",[390,3906,3908],{"className":3907},[393],[390,3909,3911,3929,3947],{"className":3910,"ariaHidden":398},[397],[390,3912,3914,3917,3920,3923,3926],{"className":3913},[402],[390,3915],{"className":3916,"style":1038},[406],[390,3918,1224],{"className":3919},[411,412],[390,3921],{"className":3922,"style":569},[568],[390,3924,1449],{"className":3925},[573],[390,3927],{"className":3928,"style":569},[568],[390,3930,3932,3935,3938,3941,3944],{"className":3931},[402],[390,3933],{"className":3934,"style":3877},[406],[390,3936,3331],{"className":3937},[411,412],[390,3939],{"className":3940,"style":3884},[568],[390,3942,3889],{"className":3943},[3888],[390,3945],{"className":3946,"style":3884},[568],[390,3948,3950,3953],{"className":3949},[402],[390,3951],{"className":3952,"style":827},[406],[390,3954,423],{"className":3955},[411],", and search, insert, and successor all degrade to ",[390,3958,3960],{"className":3959},[393],[390,3961,3963],{"className":3962,"ariaHidden":398},[397],[390,3964,3966,3969,3972,3975,3978],{"className":3965},[402],[390,3967],{"className":3968,"style":407},[406],[390,3970,3576],{"className":3971},[411],[390,3973,419],{"className":3974},[418],[390,3976,3331],{"className":3977},[411,412],[390,3979,428],{"className":3980},[427],",\nno better than scanning an unsorted array.",[702,3983,3984],{},[385,3985,3989],{"href":3986,"ariaDescribedBy":3987,"dataFootnoteRef":376,"id":3988},"#user-content-fn-clrs-height",[708],"user-content-fnref-clrs-height","4"," The very flexibility that made\ninsertion easy (new keys land as leaves wherever the path takes them) lets an\nunlucky or adversarial insertion order ruin the shape.",[381,3992,3993],{},"This is the central tension of binary search trees:",[471,3995,3997],{"type":3996},"remark",[381,3998,3999,4002,4003,4006,4007,4031,4032,4047,4048,4081,4082,4106],{},[431,4000,4001],{},"Remark (BST height tension)."," A BST is only as good as it is ",[436,4004,4005],{},"short",". Operations are ",[390,4008,4010],{"className":4009},[393],[390,4011,4013],{"className":4012,"ariaHidden":398},[397],[390,4014,4016,4019,4022,4025,4028],{"className":4015},[402],[390,4017],{"className":4018,"style":407},[406],[390,4020,414],{"className":4021,"style":413},[411,412],[390,4023,419],{"className":4024},[418],[390,4026,1224],{"className":4027},[411,412],[390,4029,428],{"className":4030},[427],", and ",[390,4033,4035],{"className":4034},[393],[390,4036,4038],{"className":4037,"ariaHidden":398},[397],[390,4039,4041,4044],{"className":4040},[402],[390,4042],{"className":4043,"style":1038},[406],[390,4045,1224],{"className":4046},[411,412]," ranges\nfrom a glorious ",[390,4049,4051],{"className":4050},[393],[390,4052,4054],{"className":4053,"ariaHidden":398},[397],[390,4055,4057,4060,4063,4066,4072,4075,4078],{"className":4056},[402],[390,4058],{"className":4059,"style":407},[406],[390,4061,3576],{"className":4062},[411],[390,4064,419],{"className":4065},[418],[390,4067,4069],{"className":4068},[3682],[390,4070,3688],{"className":4071,"style":3687},[411,3686],[390,4073],{"className":4074,"style":867},[568],[390,4076,3331],{"className":4077},[411,412],[390,4079,428],{"className":4080},[427]," down to a catastrophic ",[390,4083,4085],{"className":4084},[393],[390,4086,4088],{"className":4087,"ariaHidden":398},[397],[390,4089,4091,4094,4097,4100,4103],{"className":4090},[402],[390,4092],{"className":4093,"style":407},[406],[390,4095,3576],{"className":4096},[411],[390,4098,419],{"className":4099},[418],[390,4101,3331],{"className":4102},[411,412],[390,4104,428],{"className":4105},[427],", depending\nentirely on the order of insertions.",[381,4108,4109,4110,4113,4114,4165,4166,4199,4200,4203,4204,4207,4208,4211,4212,4245,4246,4248],{},"We cannot control the order in which keys arrive. So the fix is to make the tree\n",[436,4111,4112],{},"rebalance itself"," as keys come and go, forcing ",[390,4115,4117],{"className":4116},[393],[390,4118,4120,4138],{"className":4119,"ariaHidden":398},[397],[390,4121,4123,4126,4129,4132,4135],{"className":4122},[402],[390,4124],{"className":4125,"style":1038},[406],[390,4127,1224],{"className":4128},[411,412],[390,4130],{"className":4131,"style":569},[568],[390,4133,1449],{"className":4134},[573],[390,4136],{"className":4137,"style":569},[568],[390,4139,4141,4144,4147,4150,4156,4159,4162],{"className":4140},[402],[390,4142],{"className":4143,"style":407},[406],[390,4145,414],{"className":4146,"style":413},[411,412],[390,4148,419],{"className":4149},[418],[390,4151,4153],{"className":4152},[3682],[390,4154,3688],{"className":4155,"style":3687},[411,3686],[390,4157],{"className":4158,"style":867},[568],[390,4160,3331],{"className":4161},[411,412],[390,4163,428],{"className":4164},[427]," no matter what.\nRandomized BSTs (and treaps) achieve ",[390,4167,4169],{"className":4168},[393],[390,4170,4172],{"className":4171,"ariaHidden":398},[397],[390,4173,4175,4178,4181,4184,4190,4193,4196],{"className":4174},[402],[390,4176],{"className":4177,"style":407},[406],[390,4179,3576],{"className":4180},[411],[390,4182,419],{"className":4183},[418],[390,4185,4187],{"className":4186},[3682],[390,4188,3688],{"className":4189,"style":3687},[411,3686],[390,4191],{"className":4192,"style":867},[568],[390,4194,3331],{"className":4195},[411,412],[390,4197,428],{"className":4198},[427]," height ",[436,4201,4202],{},"in expectation",";\n",[385,4205,4206],{"href":101},"balanced search trees"," — red-black trees, ",[385,4209,4210],{"href":95},"AVL trees",", B-trees — guarantee\n",[390,4213,4215],{"className":4214},[393],[390,4216,4218],{"className":4217,"ariaHidden":398},[397],[390,4219,4221,4224,4227,4230,4236,4239,4242],{"className":4220},[402],[390,4222],{"className":4223,"style":407},[406],[390,4225,414],{"className":4226,"style":413},[411,412],[390,4228,419],{"className":4229},[418],[390,4231,4233],{"className":4232},[3682],[390,4234,3688],{"className":4235,"style":3687},[411,3686],[390,4237],{"className":4238,"style":867},[568],[390,4240,3331],{"className":4241},[411,412],[390,4243,428],{"className":4244},[427]," height in the ",[436,4247,3736],{}," by maintaining extra structural\ninvariants and repairing them after each update. That repair machinery is the\nsubject of the next lesson.",[445,4250,4252],{"id":4251},"takeaways","Takeaways",[1936,4254,4255,4296,4329,4361,4425],{},[1939,4256,383,4257,4259,4260,4263,4264,4279,4280,4295],{},[431,4258,433],{}," stores keys under the ",[431,4261,4262],{},"BST property"," (left subtree\n",[390,4265,4267],{"className":4266},[393],[390,4268,4270],{"className":4269,"ariaHidden":398},[397],[390,4271,4273,4276],{"className":4272},[402],[390,4274],{"className":4275,"style":899},[406],[390,4277,574],{"className":4278},[573]," node ",[390,4281,4283],{"className":4282},[393],[390,4284,4286],{"className":4285,"ariaHidden":398},[397],[390,4287,4289,4292],{"className":4288},[402],[390,4290],{"className":4291,"style":899},[406],[390,4293,574],{"className":4294},[573]," right subtree, recursively), so searching follows one\nroot-to-leaf path.",[1939,4297,4298,4301,4302,4326,4327,443],{},[431,4299,4300],{},"Search, insert, minimum, maximum, successor, predecessor"," all walk a single\nvertical path and cost ",[390,4303,4305],{"className":4304},[393],[390,4306,4308],{"className":4307,"ariaHidden":398},[397],[390,4309,4311,4314,4317,4320,4323],{"className":4310},[402],[390,4312],{"className":4313,"style":407},[406],[390,4315,414],{"className":4316,"style":413},[411,412],[390,4318,419],{"className":4319},[418],[390,4321,1224],{"className":4322},[411,412],[390,4324,428],{"className":4325},[427],"; new keys enter as ",[431,4328,1878],{},[1939,4330,4331,4332,4335,4336,4360],{},"An ",[431,4333,4334],{},"inorder walk"," emits the keys in sorted order in ",[390,4337,4339],{"className":4338},[393],[390,4340,4342],{"className":4341,"ariaHidden":398},[397],[390,4343,4345,4348,4351,4354,4357],{"className":4344},[402],[390,4346],{"className":4347,"style":407},[406],[390,4349,3576],{"className":4350},[411],[390,4352,419],{"className":4353},[418],[390,4355,3331],{"className":4356},[411,412],[390,4358,428],{"className":4359},[427]," time; the\norder is baked into the shape.",[1939,4362,4363,4364,2551,4366,4399,4400,4424],{},"Performance hinges entirely on ",[431,4365,442],{},[390,4367,4369],{"className":4368},[393],[390,4370,4372],{"className":4371,"ariaHidden":398},[397],[390,4373,4375,4378,4381,4384,4390,4393,4396],{"className":4374},[402],[390,4376],{"className":4377,"style":407},[406],[390,4379,3576],{"className":4380},[411],[390,4382,419],{"className":4383},[418],[390,4385,4387],{"className":4386},[3682],[390,4388,3688],{"className":4389,"style":3687},[411,3686],[390,4391],{"className":4392,"style":867},[568],[390,4394,3331],{"className":4395},[411,412],[390,4397,428],{"className":4398},[427]," when balanced,\nbut ",[390,4401,4403],{"className":4402},[393],[390,4404,4406],{"className":4405,"ariaHidden":398},[397],[390,4407,4409,4412,4415,4418,4421],{"className":4408},[402],[390,4410],{"className":4411,"style":407},[406],[390,4413,3576],{"className":4414},[411],[390,4416,419],{"className":4417},[418],[390,4419,3331],{"className":4420},[411,412],[390,4422,428],{"className":4423},[427]," for a degenerate (e.g. sorted-insertion) tree.",[1939,4426,4427,4428,4431,4432,4483],{},"Because we cannot control insertion order, we need trees that ",[431,4429,4430],{},"rebalance\nthemselves"," to guarantee ",[390,4433,4435],{"className":4434},[393],[390,4436,4438,4456],{"className":4437,"ariaHidden":398},[397],[390,4439,4441,4444,4447,4450,4453],{"className":4440},[402],[390,4442],{"className":4443,"style":1038},[406],[390,4445,1224],{"className":4446},[411,412],[390,4448],{"className":4449,"style":569},[568],[390,4451,1449],{"className":4452},[573],[390,4454],{"className":4455,"style":569},[568],[390,4457,4459,4462,4465,4468,4474,4477,4480],{"className":4458},[402],[390,4460],{"className":4461,"style":407},[406],[390,4463,414],{"className":4464,"style":413},[411,412],[390,4466,419],{"className":4467},[418],[390,4469,4471],{"className":4470},[3682],[390,4472,3688],{"className":4473,"style":3687},[411,3686],[390,4475],{"className":4476,"style":867},[568],[390,4478,3331],{"className":4479},[411,412],[390,4481,428],{"className":4482},[427],", the motivation for balanced search\ntrees.",[4485,4486,4489,4494],"section",{"className":4487,"dataFootnotes":376},[4488],"footnotes",[445,4490,4493],{"className":4491,"id":708},[4492],"sr-only","Footnotes",[2468,4495,4496,4510,4547,4559],{},[1939,4497,4499,4502,4503],{"id":4498},"user-content-fn-clrs-bst",[431,4500,4501],{},"CLRS",", Ch. 12 — Binary Search Trees (§12.1): the BST property as a recursive ordering invariant. ",[385,4504,4509],{"href":4505,"ariaLabel":4506,"className":4507,"dataFootnoteBackref":376},"#user-content-fnref-clrs-bst","Back to reference 1",[4508],"data-footnote-backref","↩",[1939,4511,4513,4516,4517,4541,4542],{"id":4512},"user-content-fn-skiena-bst",[431,4514,4515],{},"Skiena",", §3.4 — Binary Search Trees: search along a single root-to-leaf path in ",[390,4518,4520],{"className":4519},[393],[390,4521,4523],{"className":4522,"ariaHidden":398},[397],[390,4524,4526,4529,4532,4535,4538],{"className":4525},[402],[390,4527],{"className":4528,"style":407},[406],[390,4530,414],{"className":4531,"style":413},[411,412],[390,4533,419],{"className":4534},[418],[390,4536,1224],{"className":4537},[411,412],[390,4539,428],{"className":4540},[427]," time. ",[385,4543,4509],{"href":4544,"ariaLabel":4545,"className":4546,"dataFootnoteBackref":376},"#user-content-fnref-skiena-bst","Back to reference 2",[4508],[1939,4548,4550,4553,4554],{"id":4549},"user-content-fn-erickson-bst",[431,4551,4552],{},"Erickson",", Ch. — Binary Search Trees: an inorder traversal emits the keys in sorted order. ",[385,4555,4509],{"href":4556,"ariaLabel":4557,"className":4558,"dataFootnoteBackref":376},"#user-content-fnref-erickson-bst","Back to reference 3",[4508],[1939,4560,4562,4564,4565,4589,4590,4614,4615],{"id":4561},"user-content-fn-clrs-height",[431,4563,4501],{},", Ch. 12 — Binary Search Trees (§12.4): operations cost ",[390,4566,4568],{"className":4567},[393],[390,4569,4571],{"className":4570,"ariaHidden":398},[397],[390,4572,4574,4577,4580,4583,4586],{"className":4573},[402],[390,4575],{"className":4576,"style":407},[406],[390,4578,414],{"className":4579,"style":413},[411,412],[390,4581,419],{"className":4582},[418],[390,4584,1224],{"className":4585},[411,412],[390,4587,428],{"className":4588},[427],", degrading to ",[390,4591,4593],{"className":4592},[393],[390,4594,4596],{"className":4595,"ariaHidden":398},[397],[390,4597,4599,4602,4605,4608,4611],{"className":4598},[402],[390,4600],{"className":4601,"style":407},[406],[390,4603,3576],{"className":4604},[411],[390,4606,419],{"className":4607},[418],[390,4609,3331],{"className":4610},[411,412],[390,4612,428],{"className":4613},[427]," for an unbalanced tree. ",[385,4616,4509],{"href":4617,"ariaLabel":4618,"className":4619,"dataFootnoteBackref":376},"#user-content-fnref-clrs-height","Back to reference 4",[4508],[4621,4622,4623],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark-mode .shiki span {color: var(--shiki-dark-mode);background: var(--shiki-dark-mode-bg);font-style: var(--shiki-dark-mode-font-style);font-weight: var(--shiki-dark-mode-font-weight);text-decoration: var(--shiki-dark-mode-text-decoration);}html.dark-mode .shiki span {color: var(--shiki-dark-mode);background: var(--shiki-dark-mode-bg);font-style: var(--shiki-dark-mode-font-style);font-weight: var(--shiki-dark-mode-font-weight);text-decoration: var(--shiki-dark-mode-text-decoration);}",{"title":376,"searchDepth":18,"depth":18,"links":4625},[4626,4627,4628,4629,4630,4631,4632,4633,4634],{"id":447,"depth":18,"text":448},{"id":1022,"depth":18,"text":139},{"id":1719,"depth":18,"text":1720},{"id":1882,"depth":18,"text":1883},{"id":2462,"depth":18,"text":2463},{"id":3197,"depth":18,"text":3198},{"id":3589,"depth":18,"text":3590},{"id":4251,"depth":18,"text":4252},{"id":708,"depth":18,"text":4493},"A hash table gives expected O(1) lookups but throws away order: it cannot tell\nyou the smallest key, the next key after a given one, or every key in a range. A\nbinary search tree (BST) keeps those queries fast by storing keys in a\nshape that records their order. Each node holds a key and pointers to a left\nchild, a right child, and a parent; the keys are arranged so that the tree itself\nis a kind of decision diagram for searching. The result is a dynamic ordered\ndictionary supporting search, insert, delete, minimum, maximum, predecessor,\nsuccessor, and in-order traversal, every one of them in time proportional to\nthe tree's height.","md",{"moduleNumber":73,"lessonNumber":18,"order":4638},402,true,[4641,4645,4648,4651,4654],{"title":4642,"slug":4643,"difficulty":4644},"Validate Binary Search Tree","validate-binary-search-tree","Medium",{"title":4646,"slug":4647,"difficulty":4644},"Kth Smallest Element in a BST","kth-smallest-element-in-a-bst",{"title":4649,"slug":4650,"difficulty":4644},"Insert into a Binary Search Tree","insert-into-a-binary-search-tree",{"title":4652,"slug":4653,"difficulty":4644},"Delete Node in a BST","delete-node-in-a-bst",{"title":4655,"slug":4656,"difficulty":4644},"Lowest Common Ancestor of a BST","lowest-common-ancestor-of-a-binary-search-tree","---\ntitle: Binary Search Trees\nmodule: Data Structures\nmoduleNumber: 4\nlessonNumber: 2\norder: 402\nsummary: >-\n  A binary search tree keeps keys ordered so that every operation follows a\n  single root-to-leaf path. We state the BST property, give search and insert,\n  find minimum, maximum, and successor, see that an inorder walk emits the keys\n  in sorted order, and confront the catch — every operation costs $O(h)$, and a\n  carelessly built tree degrades to height $h = \\Theta(n)$, motivating balance.\ntopics: [Binary Search Trees]\nsources:\n  - book: CLRS\n    ref: \"Ch. 12 — Binary Search Trees\"\n  - book: Skiena\n    ref: \"§3.4 — Binary Search Trees\"\n  - book: Erickson\n    ref: \"Ch. — Binary Search Trees\"\npractice:\n  - title: 'Validate Binary Search Tree'\n    slug: validate-binary-search-tree\n    difficulty: Medium\n  - title: 'Kth Smallest Element in a BST'\n    slug: kth-smallest-element-in-a-bst\n    difficulty: Medium\n  - title: 'Insert into a Binary Search Tree'\n    slug: insert-into-a-binary-search-tree\n    difficulty: Medium\n  - title: 'Delete Node in a BST'\n    slug: delete-node-in-a-bst\n    difficulty: Medium\n  - title: 'Lowest Common Ancestor of a BST'\n    slug: lowest-common-ancestor-of-a-binary-search-tree\n    difficulty: Medium\n---\n\nA [hash table](\u002Falgorithms\u002Fdata-structures\u002Fhash-tables) gives expected $O(1)$ lookups but throws away order: it cannot tell\nyou the smallest key, the next key after a given one, or every key in a range. A\n**binary search tree** (BST) keeps those queries fast by storing keys in a\nshape that _records_ their order. Each node holds a key and pointers to a left\nchild, a right child, and a parent; the keys are arranged so that the tree itself\nis a kind of decision diagram for searching. The result is a dynamic ordered\ndictionary supporting search, insert, delete, minimum, maximum, predecessor,\nsuccessor, and in-order traversal, every one of them in time proportional to\nthe tree's **height**.\n\n## The binary search tree property\n\nThe arrangement is governed by one local invariant, checked at every node $x$:\n\n> **Property (BST).** For every node $x$: if $y$ is a node in the _left_ subtree of\n> $x$, then $key(y) \\le key(x)$; and if $y$ is in the _right_ subtree of $x$,\n> then $key(y) \\ge key(x)$.\n\nSmaller keys live to the left, larger keys to the right, _everywhere_, not just\nbetween a node and its immediate children.[^clrs-bst] This recursive constraint is exactly\nwhat lets a search discard half the tree at each step.\n\n$$\n% caption: A binary search tree with smaller keys left and larger keys right\n\\begin{tikzpicture}[\n  every node\u002F.style={circle, draw, minimum size=8mm, inner sep=0},\n  level distance=12mm,\n  level 1\u002F.style={sibling distance=28mm},\n  level 2\u002F.style={sibling distance=15mm}]\n  \\node {6}\n    child {node {3}\n      child {node {2}}\n      child {node {5}}\n    }\n    child {node {8}\n      child {node {7}}\n      child {node {9}}\n    };\n\\end{tikzpicture}\n$$\n\nReading this tree: the root is $6$; everything in its left subtree\n($\\set{2,3,5}$) is $\\le 6$ and everything in its right subtree\n($\\set{7,8,9}$) is $\\ge 6$, and the same holds recursively at $3$ and $8$.\n\n## Searching\n\nTo search for a key $k$, start at the root and walk down. At each node, if $k$\nequals the node's key we are done; if $k$ is smaller we go left, otherwise we go\nright. Each comparison drops us one level, so the search traces a single\nroot-to-leaf path.\n\n```algorithm\ncaption: $\\textsc{Tree-Search}(x, k)$ — find key $k$ in the subtree rooted at $x$\nif $x = \\text{nil}$ or $k = key(x)$ then\n  return $x$\nif $k \u003C key(x)$ then\n  return call $\\textsc{Tree-Search}(left(x), k)$ \u002F\u002F k is in the left subtree\nelse\n  return call $\\textsc{Tree-Search}(right(x), k)$ \u002F\u002F k is in the right subtree\n```\n\nThe procedure is correct by the BST property: when $k \u003C key(x)$, the property\nguarantees $k$ cannot be in $x$'s right subtree, so discarding it loses nothing.\nThe search visits one node per level and runs in $O(h)$ time, where $h$ is the\nheight of the tree.[^skiena-bst]\n\n$$\n% caption: Searching for $k=5$. At $6$ we go left ($5\u003C6$); at $3$ we go right ($5>3$); at $5$ we stop. The path (accent) visits one node per level, and each step discards an entire subtree (red), so the search examines just $3$ of the $7$ nodes.\n\\begin{tikzpicture}[\n  every node\u002F.style={circle, draw, minimum size=8mm, inner sep=0, font=\\small},\n  level distance=12mm,\n  level 1\u002F.style={sibling distance=26mm},\n  level 2\u002F.style={sibling distance=14mm}, >=stealth]\n  \\definecolor{acc}{HTML}{2348F2}\n  \\node (r) {6}\n    child {node (n3) {3}\n      child {node {2}}\n      child {node (n5) {5}}\n    }\n    child {node (n8) {8}\n      child {node {7}}\n      child {node {9}}\n    };\n  % discarded subtrees (red): right subtree of 6, and left child of 3\n  \\node[draw=red!75!black, very thick, minimum size=8mm, inner sep=0] at (n8) {};\n  \\node[draw=none, font=\\scriptsize, red!75!black, align=center] at (3.7,-1.2) {$5\\!\u003C\\!6$:\\\\drop right};\n  \\draw[->, red!75!black] (2.7,-1.2) -- (n8.east);\n  % search path highlights\n  \\node[draw=acc, very thick, minimum size=8mm, inner sep=0] at (r) {};\n  \\node[draw=acc, very thick, minimum size=8mm, inner sep=0] at (n3) {};\n  \\node[draw=acc, very thick, minimum size=8mm, inner sep=0] at (n5) {};\n  \\draw[->, acc, thick] (r) to[bend right=12] (n3);\n  \\draw[->, acc, thick] (n3) to[bend right=12] (n5);\n\\end{tikzpicture}\n$$ $\\textsc{Tree-Minimum}$ and $\\textsc{Tree-Maximum}$ are the degenerate\ncases of search: follow `left` pointers until they run out to reach the smallest\nkey, or `right` pointers for the largest.\n\n```algorithm\ncaption: $\\textsc{Tree-Minimum}(x)$ and $\\textsc{Tree-Maximum}(x)$\nTree-Minimum(x):\n  while $left(x) \\ne \\text{nil}$ do\n    $x \\gets left(x)$ \u002F\u002F min is the leftmost node\n  return $x$\nTree-Maximum(x):\n  while $right(x) \\ne \\text{nil}$ do\n    $x \\gets right(x)$ \u002F\u002F max is the rightmost node\n  return $x$\n```\n\n## Inserting\n\nInsertion reuses the search path. To insert key $k$, walk down as if searching\nfor it; when the walk falls off the bottom of the tree (reaches a `nil` child),\nthat empty spot is exactly where $k$ belongs, preserving the BST property. We\nattach a new leaf there, remembering the parent so we can hook it in.\n\n```algorithm\ncaption: $\\textsc{Tree-Insert}(T, z)$ — insert node $z$ (with $key(z)$ set) into BST $T$\n$y \\gets \\text{nil}$ \u002F\u002F y trails x\n$x \\gets root(T)$\nwhile $x \\ne \\text{nil}$ do\n  $y \\gets x$\n  if $key(z) \u003C key(x)$ then\n    $x \\gets left(x)$\n  else\n    $x \\gets right(x)$\n$parent(z) \\gets y$\nif $y = \\text{nil}$ then\n  $root(T) \\gets z$ \u002F\u002F tree was empty\nelse if $key(z) \u003C key(y)$ then\n  $left(y) \\gets z$\nelse\n  $right(y) \\gets z$\n```\n\nLike search, insertion walks one root-to-leaf path and costs $O(h)$. New keys\nalways enter as **leaves**, which is what keeps insertion simple, but also what\nsets up the trouble we meet below.\n\n## Finding a successor\n\nThe **successor** of a node $x$ is the node with the smallest key greater than\n$key(x)$, the next key in sorted order. There are two cases, and neither needs\na comparison of keys, only structure:\n\n- If $x$ has a right subtree, the successor is the _minimum_ of that subtree:\n  the smallest key still larger than $key(x)$.\n- If $x$ has no right subtree, the successor is the lowest ancestor whose left\n  child is also an ancestor of $x$; we climb up until we move up a _left_ link.\n\n```algorithm\ncaption: $\\textsc{Tree-Successor}(x)$ — next node in sorted order\nif $right(x) \\ne \\text{nil}$ then\n  return call $\\textsc{Tree-Minimum}(right(x))$ \u002F\u002F min of right subtree\n$y \\gets parent(x)$\nwhile $y \\ne \\text{nil}$ and $x = right(y)$ do\n  $x \\gets y$ \u002F\u002F climb while x is a right child\n  $y \\gets parent(y)$\nreturn $y$\n```\n\nBoth cases follow a single vertical path, down into the right subtree or up\nthrough ancestors, so $\\textsc{Tree-Successor}$ also runs in $O(h)$. **Predecessor**\nis the mirror image (left subtree's maximum, or climb until a right link).\n\n$$\n% caption: The two successor cases. Left: $6$ has a right subtree, so its successor is that subtree's minimum, $7$ (descend left from $8$). Right: $5$ has no right subtree, so climb until moving up a left link — $5\\to3\\to6$ — giving successor $6$.\n\\begin{tikzpicture}[\n  every node\u002F.style={circle, draw, minimum size=7mm, inner sep=0, font=\\small},\n  level distance=11mm,\n  level 1\u002F.style={sibling distance=20mm},\n  level 2\u002F.style={sibling distance=11mm}, >=stealth]\n  \\definecolor{acc}{HTML}{2348F2}\n  % LEFT panel: right-subtree-min case, x=6\n  \\begin{scope}\n    \\node (r) {6}\n      child {node {3}\n        child {node {2}}\n        child {node {5}}\n      }\n      child {node (e8) {8}\n        child {node (e7) {7}}\n        child {node {9}}\n      };\n    \\node[draw=acc, very thick, minimum size=7mm, inner sep=0] at (r) {};\n    \\node[draw=acc, very thick, minimum size=7mm, inner sep=0] at (e7) {};\n    \\draw[->, red!75!black, thick] (r) to[bend left=10] (e8);\n    \\draw[->, red!75!black, thick] (e8) to[bend left=10] (e7);\n  \\end{scope}\n  % RIGHT panel: climb case, x=5\n  \\begin{scope}[xshift=6.4cm]\n    \\node (q) {6}\n      child {node (q3) {3}\n        child {node {2}}\n        child {node (q5) {5}}\n      }\n      child {node {8}\n        child {node {7}}\n        child {node {9}}\n      };\n    \\node[draw=acc, very thick, minimum size=7mm, inner sep=0] at (q5) {};\n    \\node[draw=acc, very thick, minimum size=7mm, inner sep=0] at (q) {};\n    \\draw[->, red!75!black, thick] (q5) to[bend left=14] (q3);\n    \\draw[->, red!75!black, thick] (q3) to[bend left=14] (q);\n  \\end{scope}\n\\end{tikzpicture}\n$$\n\n## Deleting a node\n\nDeletion is the one operation that needs care, because removing an internal node\nleaves a hole that must be filled without disturbing the BST property. There are\nthree cases, in increasing difficulty:\n\n1. $z$ has **no children**: just detach it from its parent.\n2. $z$ has **one child**: splice that child into $z$'s position.\n3. $z$ has **two children**: $z$'s successor $y$ is the minimum of its right\n   subtree, so $y$ has no left child. Move $y$ into $z$'s position; if $y$ was\n   not $z$'s direct child, first replace $y$ by its own right child.\n\nAll three reduce to a single primitive, $\\textsc{Transplant}$, which replaces the\nsubtree rooted at $u$ with the subtree rooted at $v$:\n\n```algorithm\ncaption: $\\textsc{Transplant}(T, u, v)$ — put subtree $v$ where subtree $u$ was\nif $parent(u) = \\text{nil}$ then\n  $root(T) \\gets v$\nelse if $u = left(parent(u))$ then\n  $left(parent(u)) \\gets v$\nelse\n  $right(parent(u)) \\gets v$\nif $v \\ne \\text{nil}$ then\n  $parent(v) \\gets parent(u)$\n```\n\n```algorithm\ncaption: $\\textsc{Tree-Delete}(T, z)$ — remove node $z$ from the BST\nif $left(z) = \\text{nil}$ then\n  call $\\textsc{Transplant}(T, z, right(z))$ \u002F\u002F lift the right child\nelse if $right(z) = \\text{nil}$ then\n  call $\\textsc{Transplant}(T, z, left(z))$ \u002F\u002F lift the left child\nelse\n  $y \\gets$ call $\\textsc{Tree-Minimum}(right(z))$ \u002F\u002F successor, no left child\n  if $parent(y) \\ne z$ then\n    call $\\textsc{Transplant}(T, y, right(y))$ \u002F\u002F detach y, lift its right child\n    $right(y) \\gets right(z)$\n    $parent(right(y)) \\gets y$\n  call $\\textsc{Transplant}(T, z, y)$ \u002F\u002F y into z's slot\n  $left(y) \\gets left(z)$\n  $parent(left(y)) \\gets y$\n```\n\nThe two-child case is the subtle one. Replacing $z$ by its successor keeps every\nkey in $z$'s left subtree below the new root and every key in the right subtree\nabove it, so the ordering survives:\n\n$$\n% caption: Deleting a node with two children: its successor (the minimum of the right subtree, here $6$) takes its place, and the successor's own right child ($7$) fills the slot it vacated.\n\\begin{tikzpicture}[n\u002F.style={circle, draw, minimum size=7mm, font=\\small, inner sep=0pt}, >=stealth]\n  \\definecolor{acc}{HTML}{2348F2}\n  \\node[n, fill=red!18] (a) at (0,0) {5};\n  \\node[n] (a3) at (-1.3,-1.2) {3}; \\node[n] (a8) at (1.3,-1.2) {8};\n  \\node[n] (a2) at (-1.9,-2.4) {2}; \\node[n] (a4) at (-0.7,-2.4) {4};\n  \\node[n, fill=acc!16] (a6) at (0.7,-2.4) {6}; \\node[n] (a9) at (1.9,-2.4) {9};\n  \\node[n] (a7) at (1.1,-3.5) {7};\n  \\draw (a)--(a3); \\draw (a)--(a8); \\draw (a3)--(a2); \\draw (a3)--(a4); \\draw (a8)--(a6); \\draw (a8)--(a9); \\draw (a6)--(a7);\n  \\node[font=\\scriptsize] at (3.3,-1.55) {delete $5$};\n  \\draw[->, thick] (2.5,-1.9) -- (3.9,-1.9);\n  \\node[n, fill=acc!16] (b) at (6.5,0) {6};\n  \\node[n] (b3) at (5.2,-1.2) {3}; \\node[n] (b8) at (7.8,-1.2) {8};\n  \\node[n] (b2) at (4.6,-2.4) {2}; \\node[n] (b4) at (5.8,-2.4) {4};\n  \\node[n] (b7) at (7.2,-2.4) {7}; \\node[n] (b9) at (8.4,-2.4) {9};\n  \\draw (b)--(b3); \\draw (b)--(b8); \\draw (b3)--(b2); \\draw (b3)--(b4); \\draw (b8)--(b7); \\draw (b8)--(b9);\n\\end{tikzpicture}\n$$\n\nEach branch does a constant amount of pointer surgery plus at most one\n$\\textsc{Tree-Minimum}$ call, so $\\textsc{Tree-Delete}$ runs in $O(h)$ like the rest.\n\n## The order is already there: inorder walk\n\nBecause the BST property sorts keys left-to-right at every node, visiting the\ntree **in order** — left subtree, then the node, then right subtree — emits the\nkeys in increasing order.[^erickson-bst]\n\n```algorithm\ncaption: $\\textsc{Inorder-Walk}(x)$ — print the subtree at $x$ in sorted order\nif $x \\ne \\text{nil}$ then\n  call $\\textsc{Inorder-Walk}(left(x))$ \u002F\u002F smaller keys first\n  print $key(x)$\n  call $\\textsc{Inorder-Walk}(right(x))$ \u002F\u002F then larger keys\n```\n\n> **Claim.** $\\textsc{Inorder-Walk}$ on a BST prints the keys in nondecreasing order.\n\n> **Proof by induction on subtree size.** A subtree of size $0$ prints nothing,\n> vacuously sorted. For a subtree rooted at $x$ of size $n$, the recursive call on\n> $left(x)$ prints, by the induction hypothesis, all keys $\\le key(x)$ in sorted\n> order; we then print $key(x)$; then the recursive call on $right(x)$ prints all\n> keys $\\ge key(x)$ in sorted order. Concatenated, the output is sorted. $\\qed$\n\nThe walk visits each of $n$ nodes once, so it runs in $\\Theta(n)$ time. This\ngives a clean way to read out a sorted sequence, and shows that a BST is, in\neffect, a dynamic sorted list you can also splice into and search.\n\n## The catch: height is everything\n\nEvery operation above costs $O(h)$. So the BST is fast exactly when $h$ is\nsmall. The **best case** is a _balanced_ tree, where the two subtrees of each\nnode have nearly equal size; then $h = \\Theta(\\log n)$ and every operation is\n$\\Theta(\\log n)$.\n\nThe **worst case** is a disaster. Suppose we insert keys in _sorted_ order:\n$1, 2, 3, \\dots, n$. Each new key is larger than everything present, so it walks\nall the way right and attaches as the rightmost leaf. The tree degenerates into a\nsingle descending path, a glorified linked list:\n\n$$\n% caption: Sorted insertions degenerate a BST into a path of height $n-1$\n\\begin{tikzpicture}[\n  every node\u002F.style={circle, draw, minimum size=7mm, inner sep=0},\n  level distance=9mm,\n  level 1\u002F.style={sibling distance=10mm}]\n  \\node {1}\n    child[missing]\n    child {node {2}\n      child[missing]\n      child {node {3}\n        child[missing]\n        child {node {4}\n          child[missing]\n          child {node {5}}\n        }\n      }\n    };\n\\end{tikzpicture}\n$$\n\nNow $h = n - 1$, and search, insert, and successor all degrade to $\\Theta(n)$,\nno better than scanning an unsorted array.[^clrs-height] The very flexibility that made\ninsertion easy (new keys land as leaves wherever the path takes them) lets an\nunlucky or adversarial insertion order ruin the shape.\n\nThis is the central tension of binary search trees:\n\n> **Remark (BST height tension).** A BST is only as good as it is _short_. Operations are $O(h)$, and $h$ ranges\n> from a glorious $\\Theta(\\log n)$ down to a catastrophic $\\Theta(n)$, depending\n> entirely on the order of insertions.\n\nWe cannot control the order in which keys arrive. So the fix is to make the tree\n_rebalance itself_ as keys come and go, forcing $h = O(\\log n)$ no matter what.\nRandomized BSTs (and treaps) achieve $\\Theta(\\log n)$ height _in expectation_;\n[balanced search trees](\u002Falgorithms\u002Fdata-structures\u002Fbalanced-trees) — red-black trees, [AVL trees](\u002Falgorithms\u002Fdata-structures\u002Favl-trees), B-trees — guarantee\n$O(\\log n)$ height in the _worst case_ by maintaining extra structural\ninvariants and repairing them after each update. That repair machinery is the\nsubject of the next lesson.\n\n## Takeaways\n\n- A **binary search tree** stores keys under the **BST property** (left subtree\n  $\\le$ node $\\le$ right subtree, recursively), so searching follows one\n  root-to-leaf path.\n- **Search, insert, minimum, maximum, successor, predecessor** all walk a single\n  vertical path and cost $O(h)$; new keys enter as **leaves**.\n- An **inorder walk** emits the keys in sorted order in $\\Theta(n)$ time; the\n  order is baked into the shape.\n- Performance hinges entirely on **height**: $\\Theta(\\log n)$ when balanced,\n  but $\\Theta(n)$ for a degenerate (e.g. sorted-insertion) tree.\n- Because we cannot control insertion order, we need trees that **rebalance\n  themselves** to guarantee $h = O(\\log n)$, the motivation for balanced search\n  trees.\n\n[^clrs-bst]: **CLRS**, Ch. 12 — Binary Search Trees (§12.1): the BST property as a recursive ordering invariant.\n[^skiena-bst]: **Skiena**, §3.4 — Binary Search Trees: search along a single root-to-leaf path in $O(h)$ time.\n[^erickson-bst]: **Erickson**, Ch. — Binary Search Trees: an inorder traversal emits the keys in sorted order.\n[^clrs-height]: **CLRS**, Ch. 12 — Binary Search Trees (§12.4): operations cost $O(h)$, degrading to $\\Theta(n)$ for an unbalanced tree.\n",{"text":4659,"minutes":4660,"time":4661,"words":4662},"8 min read",7.93,475800,1586,{"title":89,"description":4635},[4665,4667,4669],{"book":4501,"ref":4666},"Ch. 12 — Binary Search Trees",{"book":4515,"ref":4668},"§3.4 — Binary Search Trees",{"book":4552,"ref":4670},"Ch. — Binary Search Trees","available","01.algorithms\u002F04.data-structures\u002F03.binary-search-trees",[89],"em6o09cFLKe8o0-h8dgJR2VrvKvr-iE7kjgcoBqur3s",{"\u002Falgorithms\u002Ffoundations\u002Fwhat-is-an-algorithm":4676,"\u002Falgorithms\u002Ffoundations\u002Fasymptotic-analysis":4677,"\u002Falgorithms\u002Ffoundations\u002Frecurrences":4678,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fmergesort":4679,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fquicksort":4680,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fselection":4681,"\u002Falgorithms\u002Fsorting\u002Fheaps-and-heapsort":4682,"\u002Falgorithms\u002Fsorting\u002Fsorting-lower-bounds":4683,"\u002Falgorithms\u002Fsorting\u002Flinear-time-sorting":4684,"\u002Falgorithms\u002Fdata-structures\u002Felementary-structures":4685,"\u002Falgorithms\u002Fdata-structures\u002Fhash-tables":4686,"\u002Falgorithms\u002Fdata-structures\u002Fbinary-search-trees":4662,"\u002Falgorithms\u002Fdata-structures\u002Favl-trees":4687,"\u002Falgorithms\u002Fdata-structures\u002Fbalanced-trees":4688,"\u002Falgorithms\u002Fdata-structures\u002Funion-find":4689,"\u002Falgorithms\u002Fdata-structures\u002Ffenwick-and-segment-trees":4690,"\u002Falgorithms\u002Fsequences\u002Ftwo-pointers-and-windows":4691,"\u002Falgorithms\u002Fsequences\u002Fmonotonic-stacks":4692,"\u002Falgorithms\u002Fsequences\u002Fbinary-search-on-the-answer":4693,"\u002Falgorithms\u002Fsequences\u002Fstring-matching":4694,"\u002Falgorithms\u002Fsequences\u002Ftries":4695,"\u002Falgorithms\u002Fgraphs\u002Frepresentations-and-traversal":4696,"\u002Falgorithms\u002Fgraphs\u002Ftopological-sort-and-scc":4697,"\u002Falgorithms\u002Fgraphs\u002Fminimum-spanning-trees":4698,"\u002Falgorithms\u002Fgraphs\u002Fshortest-paths":4699,"\u002Falgorithms\u002Fgraphs\u002Fnetwork-flow":4700,"\u002Falgorithms\u002Fgraphs\u002Fbridges-and-articulation-points":4701,"\u002Falgorithms\u002Fgraphs\u002Flowest-common-ancestor":4702,"\u002Falgorithms\u002Fgraphs\u002Ftwo-sat":4703,"\u002Falgorithms\u002Fgraphs\u002Feulerian-tours":4704,"\u002Falgorithms\u002Fgreedy\u002Fthe-greedy-method":4705,"\u002Falgorithms\u002Fgreedy\u002Fscheduling-and-intervals":4706,"\u002Falgorithms\u002Fgreedy\u002Fhuffman-codes":4707,"\u002Falgorithms\u002Fgreedy\u002Fmatroids":4708,"\u002Falgorithms\u002Fdynamic-programming\u002Fprinciples":4709,"\u002Falgorithms\u002Fdynamic-programming\u002Fsequence-dp":4710,"\u002Falgorithms\u002Fdynamic-programming\u002Flongest-increasing-subsequence":4711,"\u002Falgorithms\u002Fdynamic-programming\u002Fknapsack":4712,"\u002Falgorithms\u002Fdynamic-programming\u002Fcoin-change-and-unbounded":4713,"\u002Falgorithms\u002Fdynamic-programming\u002Finterval-dp":4714,"\u002Falgorithms\u002Fdynamic-programming\u002Ftree-dp":4715,"\u002Falgorithms\u002Fdynamic-programming\u002Fbitmask-dp":4716,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-optimizations":4717,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-on-graphs":4718,"\u002Falgorithms\u002Fbacktracking\u002Fbacktracking-fundamentals":4719,"\u002Falgorithms\u002Fbacktracking\u002Fconstraint-search":4720,"\u002Falgorithms\u002Fbacktracking\u002Fbranch-and-bound":4721,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fnumber-theory-basics":4691,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fmodular-exponentiation-and-primality":4722,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fsieve-and-factorization":4723,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fcombinatorics":4724,"\u002Falgorithms\u002Fcomputational-geometry\u002Fgeometric-primitives":4725,"\u002Falgorithms\u002Fcomputational-geometry\u002Fconvex-hull":4707,"\u002Falgorithms\u002Fcomputational-geometry\u002Fsweep-line":4726,"\u002Falgorithms\u002Fintractability\u002Fp-np-reductions":4727,"\u002Falgorithms\u002Fintractability\u002Fnp-completeness":4687,"\u002Falgorithms\u002Fintractability\u002Fcoping-with-hardness":4728,"\u002Falgorithms":4729,"\u002Ftheory-of-computation":4730,"\u002Fcomputer-architecture":4730,"\u002Fphysical-computing":4730,"\u002Fdatabases":4730,"\u002Fdeep-learning":4730},1763,2107,1738,2628,1723,2048,1697,1044,1542,1565,1679,1388,1465,1971,1455,1533,1483,1578,1791,1481,2704,1658,2070,1978,2080,1568,1451,1291,1543,1883,1443,1599,2038,2241,1744,1678,2288,1929,1657,1412,1554,1418,1713,1798,1694,1762,1534,1595,1262,1495,1630,2306,2142,107,0,{"\u002Falgorithms\u002Ffoundations\u002Fwhat-is-an-algorithm":4732,"\u002Falgorithms\u002Ffoundations\u002Fasymptotic-analysis":4733,"\u002Falgorithms\u002Ffoundations\u002Frecurrences":4734,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fmergesort":4735,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fquicksort":4736,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fselection":4737,"\u002Falgorithms\u002Fsorting\u002Fheaps-and-heapsort":4738,"\u002Falgorithms\u002Fsorting\u002Fsorting-lower-bounds":4739,"\u002Falgorithms\u002Fsorting\u002Flinear-time-sorting":4740,"\u002Falgorithms\u002Fdata-structures\u002Felementary-structures":4741,"\u002Falgorithms\u002Fdata-structures\u002Fhash-tables":4742,"\u002Falgorithms\u002Fdata-structures\u002Fbinary-search-trees":4743,"\u002Falgorithms\u002Fdata-structures\u002Favl-trees":4744,"\u002Falgorithms\u002Fdata-structures\u002Fbalanced-trees":4745,"\u002Falgorithms\u002Fdata-structures\u002Funion-find":4746,"\u002Falgorithms\u002Fdata-structures\u002Ffenwick-and-segment-trees":4747,"\u002Falgorithms\u002Fsequences\u002Ftwo-pointers-and-windows":4748,"\u002Falgorithms\u002Fsequences\u002Fmonotonic-stacks":4749,"\u002Falgorithms\u002Fsequences\u002Fbinary-search-on-the-answer":4750,"\u002Falgorithms\u002Fsequences\u002Fstring-matching":4751,"\u002Falgorithms\u002Fsequences\u002Ftries":4752,"\u002Falgorithms\u002Fgraphs\u002Frepresentations-and-traversal":4753,"\u002Falgorithms\u002Fgraphs\u002Ftopological-sort-and-scc":4754,"\u002Falgorithms\u002Fgraphs\u002Fminimum-spanning-trees":4755,"\u002Falgorithms\u002Fgraphs\u002Fshortest-paths":4756,"\u002Falgorithms\u002Fgraphs\u002Fnetwork-flow":4757,"\u002Falgorithms\u002Fgraphs\u002Fbridges-and-articulation-points":4758,"\u002Falgorithms\u002Fgraphs\u002Flowest-common-ancestor":4759,"\u002Falgorithms\u002Fgraphs\u002Ftwo-sat":4760,"\u002Falgorithms\u002Fgraphs\u002Feulerian-tours":4761,"\u002Falgorithms\u002Fgreedy\u002Fthe-greedy-method":4762,"\u002Falgorithms\u002Fgreedy\u002Fscheduling-and-intervals":4763,"\u002Falgorithms\u002Fgreedy\u002Fhuffman-codes":4764,"\u002Falgorithms\u002Fgreedy\u002Fmatroids":4765,"\u002Falgorithms\u002Fdynamic-programming\u002Fprinciples":4766,"\u002Falgorithms\u002Fdynamic-programming\u002Fsequence-dp":4767,"\u002Falgorithms\u002Fdynamic-programming\u002Flongest-increasing-subsequence":4768,"\u002Falgorithms\u002Fdynamic-programming\u002Fknapsack":4769,"\u002Falgorithms\u002Fdynamic-programming\u002Fcoin-change-and-unbounded":4770,"\u002Falgorithms\u002Fdynamic-programming\u002Finterval-dp":4771,"\u002Falgorithms\u002Fdynamic-programming\u002Ftree-dp":4772,"\u002Falgorithms\u002Fdynamic-programming\u002Fbitmask-dp":4773,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-optimizations":4774,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-on-graphs":4775,"\u002Falgorithms\u002Fbacktracking\u002Fbacktracking-fundamentals":4776,"\u002Falgorithms\u002Fbacktracking\u002Fconstraint-search":4777,"\u002Falgorithms\u002Fbacktracking\u002Fbranch-and-bound":4778,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fnumber-theory-basics":4779,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fmodular-exponentiation-and-primality":4780,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fsieve-and-factorization":4781,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fcombinatorics":4782,"\u002Falgorithms\u002Fcomputational-geometry\u002Fgeometric-primitives":4783,"\u002Falgorithms\u002Fcomputational-geometry\u002Fconvex-hull":4784,"\u002Falgorithms\u002Fcomputational-geometry\u002Fsweep-line":4785,"\u002Falgorithms\u002Fintractability\u002Fp-np-reductions":4786,"\u002Falgorithms\u002Fintractability\u002Fnp-completeness":4787,"\u002Falgorithms\u002Fintractability\u002Fcoping-with-hardness":4788,"\u002Falgorithms":4789,"\u002Ftheory-of-computation":4792,"\u002Fcomputer-architecture":4795,"\u002Fphysical-computing":4798,"\u002Fdatabases":4801,"\u002Fdeep-learning":4804},{"path":11,"title":10,"module":5,"summary":14},{"path":17,"title":16,"module":5,"summary":20},{"path":23,"title":22,"module":5,"summary":27},{"path":34,"title":33,"module":29,"summary":37},{"path":40,"title":39,"module":29,"summary":43},{"path":46,"title":45,"module":29,"summary":49},{"path":56,"title":55,"module":51,"summary":59},{"path":62,"title":61,"module":51,"summary":64},{"path":67,"title":66,"module":51,"summary":70},{"path":78,"title":77,"module":72,"summary":81},{"path":84,"title":83,"module":72,"summary":87},{"path":90,"title":89,"module":72,"summary":92},{"path":95,"title":94,"module":72,"summary":98},{"path":101,"title":100,"module":72,"summary":104},{"path":107,"title":106,"module":72,"summary":112},{"path":115,"title":114,"module":72,"summary":119},{"path":126,"title":125,"module":121,"summary":129},{"path":132,"title":131,"module":121,"summary":134},{"path":137,"title":136,"module":121,"summary":140},{"path":143,"title":142,"module":121,"summary":146},{"path":149,"title":148,"module":121,"summary":151},{"path":158,"title":157,"module":153,"summary":162},{"path":165,"title":164,"module":153,"summary":167},{"path":170,"title":169,"module":153,"summary":172},{"path":175,"title":174,"module":153,"summary":177},{"path":180,"title":179,"module":153,"summary":182},{"path":185,"title":184,"module":153,"summary":187},{"path":190,"title":189,"module":153,"summary":192},{"path":195,"title":194,"module":153,"summary":198},{"path":201,"title":200,"module":153,"summary":204},{"path":211,"title":210,"module":206,"summary":213},{"path":216,"title":215,"module":206,"summary":219},{"path":222,"title":221,"module":206,"summary":224},{"path":227,"title":226,"module":206,"summary":229},{"path":236,"title":235,"module":231,"summary":238},{"path":241,"title":240,"module":231,"summary":244},{"path":247,"title":246,"module":231,"summary":249},{"path":252,"title":251,"module":231,"summary":254},{"path":257,"title":256,"module":231,"summary":259},{"path":262,"title":261,"module":231,"summary":264},{"path":267,"title":266,"module":231,"summary":269},{"path":272,"title":271,"module":231,"summary":274},{"path":277,"title":276,"module":231,"summary":279},{"path":282,"title":281,"module":231,"summary":285},{"path":292,"title":291,"module":287,"summary":295},{"path":298,"title":297,"module":287,"summary":300},{"path":303,"title":302,"module":287,"summary":305},{"path":312,"title":311,"module":307,"summary":315},{"path":318,"title":317,"module":307,"summary":320},{"path":323,"title":322,"module":307,"summary":325},{"path":328,"title":327,"module":307,"summary":330},{"path":338,"title":337,"module":332,"summary":341},{"path":344,"title":343,"module":332,"summary":346},{"path":349,"title":348,"module":332,"summary":351},{"path":359,"title":358,"module":353,"summary":362},{"path":364,"title":361,"module":353,"summary":366},{"path":369,"title":368,"module":353,"summary":373},{"path":4790,"title":4791,"module":376,"summary":376},"\u002Falgorithms","Algorithms",{"path":4793,"title":4794,"module":376,"summary":376},"\u002Ftheory-of-computation","Theory of Computation",{"path":4796,"title":4797,"module":376,"summary":376},"\u002Fcomputer-architecture","Computer Architecture",{"path":4799,"title":4800,"module":376,"summary":376},"\u002Fphysical-computing","Physical Computing",{"path":4802,"title":4803,"module":376,"summary":376},"\u002Fdatabases","Databases",{"path":4805,"title":4806,"module":376,"summary":376},"\u002Fdeep-learning","Deep Learning",1781526654633]