[{"data":1,"prerenderedAt":7367},["ShallowReactive",2],{"nav:algorithms":3,"lesson:\u002Falgorithms\u002Fgraphs\u002Flowest-common-ancestor":374,"course-wordcounts":7235,"ref-card-index":7291},[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":189,"blurb":376,"body":377,"description":7197,"extension":7198,"meta":7199,"module":153,"navigation":7201,"path":190,"practice":7202,"rawbody":7217,"readingTime":7218,"seo":7223,"sources":7224,"status":7231,"stem":7232,"summary":192,"topics":7233,"__hash__":7234},"course\u002F01.algorithms\u002F06.graphs\u002F07.lowest-common-ancestor.md","",{"type":378,"value":379,"toc":7183},"minimark",[380,438,658,693,698,727,780,978,982,1078,1305,1407,1604,1958,2143,2183,2325,2594,2647,2810,2845,2921,3198,3235,3474,3524,3814,3959,4074,4199,4203,4320,4605,4975,4979,5081,5266,5512,5516,5528,5810,6144,6218,6349,6353,7023,7179],[381,382,383,384,388,389,414,415,432,433,437],"p",{},"The previous lessons gave us a rooted tree and a single root-to-node path for\neach vertex. Many problems instead ask about ",[385,386,387],"em",{},"two"," vertices at once: how far\napart are ",[390,391,394],"span",{"className":392},[393],"katex",[390,395,399],{"className":396,"ariaHidden":398},[397],"katex-html","true",[390,400,403,408],{"className":401},[402],"base",[390,404],{"className":405,"style":407},[406],"strut","height:0.4306em;",[390,409,413],{"className":410},[411,412],"mord","mathnormal","u"," and ",[390,416,418],{"className":417},[393],[390,419,421],{"className":420,"ariaHidden":398},[397],[390,422,424,427],{"className":423},[402],[390,425],{"className":426,"style":407},[406],[390,428,431],{"className":429,"style":430},[411,412],"margin-right:0.0359em;","v","? what is the highest fork their paths share? which company\ncontains both of two nested regions? Each reduces to one question: the ",[434,435,436],"strong",{},"lowest\ncommon ancestor",".",[439,440,442],"callout",{"type":441},"definition",[381,443,444,447,448,465,466,484,485,501,502,505,506,521,522,537,538,553,554,569,570,573,574,622,623,414,638,653,654,657],{},[434,445,446],{},"Definition."," Fix a root ",[390,449,451],{"className":450},[393],[390,452,454],{"className":453,"ariaHidden":398},[397],[390,455,457,460],{"className":456},[402],[390,458],{"className":459,"style":407},[406],[390,461,464],{"className":462,"style":463},[411,412],"margin-right:0.0278em;","r"," of a tree ",[390,467,469],{"className":468},[393],[390,470,472],{"className":471,"ariaHidden":398},[397],[390,473,475,479],{"className":474},[402],[390,476],{"className":477,"style":478},[406],"height:0.6833em;",[390,480,483],{"className":481,"style":482},[411,412],"margin-right:0.1389em;","T",". A node ",[390,486,488],{"className":487},[393],[390,489,491],{"className":490,"ariaHidden":398},[397],[390,492,494,497],{"className":493},[402],[390,495],{"className":496,"style":407},[406],[390,498,500],{"className":499},[411,412],"a"," is an ",[434,503,504],{},"ancestor"," of\n",[390,507,509],{"className":508},[393],[390,510,512],{"className":511,"ariaHidden":398},[397],[390,513,515,518],{"className":514},[402],[390,516],{"className":517,"style":407},[406],[390,519,431],{"className":520,"style":430},[411,412]," if ",[390,523,525],{"className":524},[393],[390,526,528],{"className":527,"ariaHidden":398},[397],[390,529,531,534],{"className":530},[402],[390,532],{"className":533,"style":407},[406],[390,535,500],{"className":536},[411,412]," lies on the path from ",[390,539,541],{"className":540},[393],[390,542,544],{"className":543,"ariaHidden":398},[397],[390,545,547,550],{"className":546},[402],[390,548],{"className":549,"style":407},[406],[390,551,464],{"className":552,"style":463},[411,412]," to ",[390,555,557],{"className":556},[393],[390,558,560],{"className":559,"ariaHidden":398},[397],[390,561,563,566],{"className":562},[402],[390,564],{"className":565,"style":407},[406],[390,567,431],{"className":568,"style":430},[411,412]," (every node is its own ancestor).\nThe ",[434,571,572],{},"lowest common ancestor"," ",[390,575,577],{"className":576},[393],[390,578,580],{"className":579,"ariaHidden":398},[397],[390,581,583,587,596,601,604,609,614,617],{"className":582},[402],[390,584],{"className":585,"style":586},[406],"height:1em;vertical-align:-0.25em;",[390,588,591],{"className":589},[590],"mop",[390,592,595],{"className":593},[411,594],"mathrm","lca",[390,597,600],{"className":598},[599],"mopen","(",[390,602,413],{"className":603},[411,412],[390,605,608],{"className":606},[607],"mpunct",",",[390,610],{"className":611,"style":613},[612],"mspace","margin-right:0.1667em;",[390,615,431],{"className":616,"style":430},[411,412],[390,618,621],{"className":619},[620],"mclose",")"," is the ancestor of\nboth ",[390,624,626],{"className":625},[393],[390,627,629],{"className":628,"ariaHidden":398},[397],[390,630,632,635],{"className":631},[402],[390,633],{"className":634,"style":407},[406],[390,636,413],{"className":637},[411,412],[390,639,641],{"className":640},[393],[390,642,644],{"className":643,"ariaHidden":398},[397],[390,645,647,650],{"className":646},[402],[390,648],{"className":649,"style":407},[406],[390,651,431],{"className":652,"style":430},[411,412]," that is ",[434,655,656],{},"deepest"," — farthest from the root.",[381,659,660,661,676,677,692],{},"The LCA is well defined and unique: the sets of ancestors of ",[390,662,664],{"className":663},[393],[390,665,667],{"className":666,"ariaHidden":398},[397],[390,668,670,673],{"className":669},[402],[390,671],{"className":672,"style":407},[406],[390,674,413],{"className":675},[411,412]," and of ",[390,678,680],{"className":679},[393],[390,681,683],{"className":682,"ariaHidden":398},[397],[390,684,686,689],{"className":685},[402],[390,687],{"className":688,"style":407},[406],[390,690,431],{"className":691,"style":430},[411,412]," are\neach a chain from the root, so their intersection is a chain, and a finite chain\nhas a unique deepest element.",[694,695,697],"h2",{"id":696},"the-naive-walk","The naive walk",[381,699,700,701,726],{},"If every node stores a parent pointer and a depth, one query is easy. Lift the\ndeeper of ",[390,702,704],{"className":703},[393],[390,705,707],{"className":706,"ariaHidden":398},[397],[390,708,710,714,717,720,723],{"className":709},[402],[390,711],{"className":712,"style":713},[406],"height:0.625em;vertical-align:-0.1944em;",[390,715,413],{"className":716},[411,412],[390,718,608],{"className":719},[607],[390,721],{"className":722,"style":613},[612],[390,724,431],{"className":725,"style":430},[411,412]," until both sit at the same depth, then advance both pointers up\nin lockstep; the first node they agree on is the LCA.",[728,729,733],"pre",{"className":730,"code":731,"language":732,"meta":376,"style":376},"language-algorithm shiki shiki-themes Vesper Light - Orange Boost (Quick Open Adjusted) vesper","caption: $\\textsc{Naive-LCA}(u, v)$ — climb to equal depth, then together\nwhile $depth[u] > depth[v]$ do\n  $u \\gets parent[u]$\nwhile $depth[v] > depth[u]$ do\n  $v \\gets parent[v]$\nwhile $u \\ne v$ do\n  $u \\gets parent[u]$\n  $v \\gets parent[v]$\nreturn $u$\n","algorithm",[734,735,736,742,747,752,757,762,767,771,775],"code",{"__ignoreMap":376},[390,737,739],{"class":738,"line":6},"line",[390,740,741],{},"caption: $\\textsc{Naive-LCA}(u, v)$ — climb to equal depth, then together\n",[390,743,744],{"class":738,"line":18},[390,745,746],{},"while $depth[u] > depth[v]$ do\n",[390,748,749],{"class":738,"line":24},[390,750,751],{},"  $u \\gets parent[u]$\n",[390,753,754],{"class":738,"line":73},[390,755,756],{},"while $depth[v] > depth[u]$ do\n",[390,758,759],{"class":738,"line":102},[390,760,761],{},"  $v \\gets parent[v]$\n",[390,763,764],{"class":738,"line":108},[390,765,766],{},"while $u \\ne v$ do\n",[390,768,769],{"class":738,"line":116},[390,770,751],{},[390,772,773],{"class":738,"line":196},[390,774,761],{},[390,776,777],{"class":738,"line":202},[390,778,779],{},"return $u$\n",[381,781,782,783,809,810,826,827,884,885,928,929,945,946,973,974,977],{},"This needs no preprocessing and is correct, but each step moves up one edge, so a\nquery costs ",[390,784,786],{"className":785},[393],[390,787,789],{"className":788,"ariaHidden":398},[397],[390,790,792,795,799,802,806],{"className":791},[402],[390,793],{"className":794,"style":586},[406],[390,796,798],{"className":797,"style":463},[411,412],"O",[390,800,600],{"className":801},[599],[390,803,805],{"className":804},[411,412],"h",[390,807,621],{"className":808},[620]," where ",[390,811,813],{"className":812},[393],[390,814,816],{"className":815,"ariaHidden":398},[397],[390,817,819,823],{"className":818},[402],[390,820],{"className":821,"style":822},[406],"height:0.6944em;",[390,824,805],{"className":825},[411,412]," is the tree's height. On a balanced tree ",[390,828,830],{"className":829},[393],[390,831,833,854],{"className":832,"ariaHidden":398},[397],[390,834,836,839,842,846,851],{"className":835},[402],[390,837],{"className":838,"style":822},[406],[390,840,805],{"className":841},[411,412],[390,843],{"className":844,"style":845},[612],"margin-right:0.2778em;",[390,847,850],{"className":848},[849],"mrel","=",[390,852],{"className":853,"style":845},[612],[390,855,857,860,863,866,874,877,881],{"className":856},[402],[390,858],{"className":859,"style":586},[406],[390,861,798],{"className":862,"style":463},[411,412],[390,864,600],{"className":865},[599],[390,867,869],{"className":868},[590],[390,870,873],{"className":871,"style":872},[411,594],"margin-right:0.0139em;","log",[390,875],{"className":876,"style":613},[612],[390,878,880],{"className":879},[411,412],"n",[390,882,621],{"className":883},[620],", but on a degenerate path ",[390,886,888],{"className":887},[393],[390,889,891,909],{"className":890,"ariaHidden":398},[397],[390,892,894,897,900,903,906],{"className":893},[402],[390,895],{"className":896,"style":822},[406],[390,898,805],{"className":899},[411,412],[390,901],{"className":902,"style":845},[612],[390,904,850],{"className":905},[849],[390,907],{"className":908,"style":845},[612],[390,910,912,915,919,922,925],{"className":911},[402],[390,913],{"className":914,"style":586},[406],[390,916,918],{"className":917},[411],"Θ",[390,920,600],{"className":921},[599],[390,923,880],{"className":924},[411,412],[390,926,621],{"className":927},[620],", and ",[390,930,932],{"className":931},[393],[390,933,935],{"className":934,"ariaHidden":398},[397],[390,936,938,941],{"className":937},[402],[390,939],{"className":940,"style":713},[406],[390,942,944],{"className":943,"style":430},[411,412],"q"," queries cost\n",[390,947,949],{"className":948},[393],[390,950,952],{"className":951,"ariaHidden":398},[397],[390,953,955,958,961,964,967,970],{"className":954},[402],[390,956],{"className":957,"style":586},[406],[390,959,798],{"className":960,"style":463},[411,412],[390,962,600],{"className":963},[599],[390,965,944],{"className":966,"style":430},[411,412],[390,968,880],{"className":969},[411,412],[390,971,621],{"className":972},[620],". We want a query cost that does not depend on shape. (For the asymptotic\nnotation, see ",[500,975,976],{"href":17},"asymptotic analysis",".)",[694,979,981],{"id":980},"binary-lifting","Binary lifting",[381,983,984,985,988,989,1004,1005,1022,1023,1077],{},"The fix is to make each jump cover an exponentially larger distance. Instead of\n",[944,986,987],{},"go up one,"," precompute, for every node ",[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":407},[406],[390,1002,431],{"className":1003,"style":430},[411,412]," and every ",[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":822},[406],[390,1018,1021],{"className":1019,"style":1020},[411,412],"margin-right:0.0315em;","k",", a pointer that goes up\n",[390,1024,1026],{"className":1025},[393],[390,1027,1029],{"className":1028,"ariaHidden":398},[397],[390,1030,1032,1036],{"className":1031},[402],[390,1033],{"className":1034,"style":1035},[406],"height:0.8491em;",[390,1037,1039,1043],{"className":1038},[411],[390,1040,1042],{"className":1041},[411],"2",[390,1044,1047],{"className":1045},[1046],"msupsub",[390,1048,1051],{"className":1049},[1050],"vlist-t",[390,1052,1055],{"className":1053},[1054],"vlist-r",[390,1056,1059],{"className":1057,"style":1035},[1058],"vlist",[390,1060,1062,1067],{"style":1061},"top:-3.063em;margin-right:0.05em;",[390,1063],{"className":1064,"style":1066},[1065],"pstrut","height:2.7em;",[390,1068,1074],{"className":1069},[1070,1071,1072,1073],"sizing","reset-size6","size3","mtight",[390,1075,1021],{"className":1076,"style":1020},[411,412,1073]," edges at once.",[439,1079,1080],{"type":441},[381,1081,1082,1084,1085,1123,1124,1165,1166,1181,1182,1223,1224,437],{},[434,1083,446],{}," Let ",[390,1086,1088],{"className":1087},[393],[390,1089,1091],{"className":1090,"ariaHidden":398},[397],[390,1092,1094,1097,1100,1103,1107,1110,1114,1117,1120],{"className":1093},[402],[390,1095],{"className":1096,"style":586},[406],[390,1098,413],{"className":1099},[411,412],[390,1101,381],{"className":1102},[411,412],[390,1104,1106],{"className":1105},[599],"[",[390,1108,431],{"className":1109,"style":430},[411,412],[390,1111,1113],{"className":1112},[620],"]",[390,1115,1106],{"className":1116},[599],[390,1118,1021],{"className":1119,"style":1020},[411,412],[390,1121,1113],{"className":1122},[620]," be the ",[390,1125,1127],{"className":1126},[393],[390,1128,1130],{"className":1129,"ariaHidden":398},[397],[390,1131,1133,1136],{"className":1132},[402],[390,1134],{"className":1135,"style":1035},[406],[390,1137,1139,1142],{"className":1138},[411],[390,1140,1042],{"className":1141},[411],[390,1143,1145],{"className":1144},[1046],[390,1146,1148],{"className":1147},[1050],[390,1149,1151],{"className":1150},[1054],[390,1152,1154],{"className":1153,"style":1035},[1058],[390,1155,1156,1159],{"style":1061},[390,1157],{"className":1158,"style":1066},[1065],[390,1160,1162],{"className":1161},[1070,1071,1072,1073],[390,1163,1021],{"className":1164,"style":1020},[411,412,1073],"-th ancestor of ",[390,1167,1169],{"className":1168},[393],[390,1170,1172],{"className":1171,"ariaHidden":398},[397],[390,1173,1175,1178],{"className":1174},[402],[390,1176],{"className":1177,"style":407},[406],[390,1179,431],{"className":1180,"style":430},[411,412],", the node\nreached by following parent pointers ",[390,1183,1185],{"className":1184},[393],[390,1186,1188],{"className":1187,"ariaHidden":398},[397],[390,1189,1191,1194],{"className":1190},[402],[390,1192],{"className":1193,"style":1035},[406],[390,1195,1197,1200],{"className":1196},[411],[390,1198,1042],{"className":1199},[411],[390,1201,1203],{"className":1202},[1046],[390,1204,1206],{"className":1205},[1050],[390,1207,1209],{"className":1208},[1054],[390,1210,1212],{"className":1211,"style":1035},[1058],[390,1213,1214,1217],{"style":1061},[390,1215],{"className":1216,"style":1066},[1065],[390,1218,1220],{"className":1219},[1070,1071,1072,1073],[390,1221,1021],{"className":1222,"style":1020},[411,412,1073]," times (or the root, if that would\nclimb past it). In particular ",[390,1225,1227],{"className":1226},[393],[390,1228,1230,1270],{"className":1229,"ariaHidden":398},[397],[390,1231,1233,1236,1239,1242,1245,1248,1251,1254,1258,1261,1264,1267],{"className":1232},[402],[390,1234],{"className":1235,"style":586},[406],[390,1237,413],{"className":1238},[411,412],[390,1240,381],{"className":1241},[411,412],[390,1243,1106],{"className":1244},[599],[390,1246,431],{"className":1247,"style":430},[411,412],[390,1249,1113],{"className":1250},[620],[390,1252,1106],{"className":1253},[599],[390,1255,1257],{"className":1256},[411],"0",[390,1259,1113],{"className":1260},[620],[390,1262],{"className":1263,"style":845},[612],[390,1265,850],{"className":1266},[849],[390,1268],{"className":1269,"style":845},[612],[390,1271,1273,1276,1279,1282,1285,1289,1292,1296,1299,1302],{"className":1272},[402],[390,1274],{"className":1275,"style":586},[406],[390,1277,381],{"className":1278},[411,412],[390,1280,500],{"className":1281},[411,412],[390,1283,464],{"className":1284,"style":463},[411,412],[390,1286,1288],{"className":1287},[411,412],"e",[390,1290,880],{"className":1291},[411,412],[390,1293,1295],{"className":1294},[411,412],"t",[390,1297,1106],{"className":1298},[599],[390,1300,431],{"className":1301,"style":430},[411,412],[390,1303,1113],{"className":1304},[620],[381,1306,1307,1308,1349,1350,1403,1404,437],{},"The whole table is built from a single doubling identity: climbing ",[390,1309,1311],{"className":1310},[393],[390,1312,1314],{"className":1313,"ariaHidden":398},[397],[390,1315,1317,1320],{"className":1316},[402],[390,1318],{"className":1319,"style":1035},[406],[390,1321,1323,1326],{"className":1322},[411],[390,1324,1042],{"className":1325},[411],[390,1327,1329],{"className":1328},[1046],[390,1330,1332],{"className":1331},[1050],[390,1333,1335],{"className":1334},[1054],[390,1336,1338],{"className":1337,"style":1035},[1058],[390,1339,1340,1343],{"style":1061},[390,1341],{"className":1342,"style":1066},[1065],[390,1344,1346],{"className":1345},[1070,1071,1072,1073],[390,1347,1021],{"className":1348,"style":1020},[411,412,1073]," edges is\nclimbing ",[390,1351,1353],{"className":1352},[393],[390,1354,1356],{"className":1355,"ariaHidden":398},[397],[390,1357,1359,1362],{"className":1358},[402],[390,1360],{"className":1361,"style":1035},[406],[390,1363,1365,1368],{"className":1364},[411],[390,1366,1042],{"className":1367},[411],[390,1369,1371],{"className":1370},[1046],[390,1372,1374],{"className":1373},[1050],[390,1375,1377],{"className":1376},[1054],[390,1378,1380],{"className":1379,"style":1035},[1058],[390,1381,1382,1385],{"style":1061},[390,1383],{"className":1384,"style":1066},[1065],[390,1386,1388],{"className":1387},[1070,1071,1072,1073],[390,1389,1391,1394,1399],{"className":1390},[411,1073],[390,1392,1021],{"className":1393,"style":1020},[411,412,1073],[390,1395,1398],{"className":1396},[1397,1073],"mbin","−",[390,1400,1402],{"className":1401},[411,1073],"1"," edges ",[385,1405,1406],{},"twice",[439,1408,1410],{"type":1409},"lemma",[381,1411,1412,1415,1416,1452,1453],{},[434,1413,1414],{},"Lemma (doubling)."," For ",[390,1417,1419],{"className":1418},[393],[390,1420,1422,1442],{"className":1421,"ariaHidden":398},[397],[390,1423,1425,1429,1432,1435,1439],{"className":1424},[402],[390,1426],{"className":1427,"style":1428},[406],"height:0.8304em;vertical-align:-0.136em;",[390,1430,1021],{"className":1431,"style":1020},[411,412],[390,1433],{"className":1434,"style":845},[612],[390,1436,1438],{"className":1437},[849],"≥",[390,1440],{"className":1441,"style":845},[612],[390,1443,1445,1449],{"className":1444},[402],[390,1446],{"className":1447,"style":1448},[406],"height:0.6444em;",[390,1450,1402],{"className":1451},[411],",\n",[390,1454,1456],{"className":1455},[393],[390,1457,1459,1498,1553,1589],{"className":1458,"ariaHidden":398},[397],[390,1460,1462,1465,1468,1471,1474,1477,1480,1483,1486,1489,1492,1495],{"className":1461},[402],[390,1463],{"className":1464,"style":586},[406],[390,1466,413],{"className":1467},[411,412],[390,1469,381],{"className":1470},[411,412],[390,1472,1106],{"className":1473},[599],[390,1475,431],{"className":1476,"style":430},[411,412],[390,1478,1113],{"className":1479},[620],[390,1481,1106],{"className":1482},[599],[390,1484,1021],{"className":1485,"style":1020},[411,412],[390,1487,1113],{"className":1488},[620],[390,1490],{"className":1491,"style":845},[612],[390,1493,850],{"className":1494},[849],[390,1496],{"className":1497,"style":845},[612],[390,1499,1501,1505,1508,1511,1519,1522,1525,1528,1531,1534,1537,1540,1543,1547,1550],{"className":1500},[402],[390,1502],{"className":1503,"style":1504},[406],"height:1.2em;vertical-align:-0.35em;",[390,1506,413],{"className":1507},[411,412],[390,1509,381],{"className":1510},[411,412],[390,1512,1514],{"className":1513},[599],[390,1515,1106],{"className":1516},[1517,1518],"delimsizing","size1",[390,1520],{"className":1521,"style":613},[612],[390,1523,413],{"className":1524},[411,412],[390,1526,381],{"className":1527},[411,412],[390,1529,1106],{"className":1530},[599],[390,1532,431],{"className":1533,"style":430},[411,412],[390,1535,1113],{"className":1536},[620],[390,1538,1106],{"className":1539},[599],[390,1541,1021],{"className":1542,"style":1020},[411,412],[390,1544],{"className":1545,"style":1546},[612],"margin-right:0.2222em;",[390,1548,1398],{"className":1549},[1397],[390,1551],{"className":1552,"style":1546},[612],[390,1554,1556,1559,1562,1565,1568,1574,1577,1580,1583,1586],{"className":1555},[402],[390,1557],{"className":1558,"style":1504},[406],[390,1560,1402],{"className":1561},[411],[390,1563,1113],{"className":1564},[620],[390,1566],{"className":1567,"style":613},[612],[390,1569,1571],{"className":1570},[620],[390,1572,1113],{"className":1573},[1517,1518],[390,1575,1106],{"className":1576},[599],[390,1578,1021],{"className":1579,"style":1020},[411,412],[390,1581],{"className":1582,"style":1546},[612],[390,1584,1398],{"className":1585},[1397],[390,1587],{"className":1588,"style":1546},[612],[390,1590,1592,1595,1598,1601],{"className":1591},[402],[390,1593],{"className":1594,"style":586},[406],[390,1596,1402],{"className":1597},[411],[390,1599,1113],{"className":1600},[620],[390,1602,437],{"className":1603},[411],[439,1605,1607],{"type":1606},"proof",[381,1608,1609,573,1612,1666,1667,1717,1718,1733,1734,1784,1785,1934,1935],{},[434,1610,1611],{},"Proof.",[390,1613,1615],{"className":1614},[393],[390,1616,1618,1654],{"className":1617,"ariaHidden":398},[397],[390,1619,1621,1624,1627,1630,1633,1636,1639,1642,1645,1648,1651],{"className":1620},[402],[390,1622],{"className":1623,"style":586},[406],[390,1625,413],{"className":1626},[411,412],[390,1628,381],{"className":1629},[411,412],[390,1631,1106],{"className":1632},[599],[390,1634,431],{"className":1635,"style":430},[411,412],[390,1637,1113],{"className":1638},[620],[390,1640,1106],{"className":1641},[599],[390,1643,1021],{"className":1644,"style":1020},[411,412],[390,1646],{"className":1647,"style":1546},[612],[390,1649,1398],{"className":1650},[1397],[390,1652],{"className":1653,"style":1546},[612],[390,1655,1657,1660,1663],{"className":1656},[402],[390,1658],{"className":1659,"style":586},[406],[390,1661,1402],{"className":1662},[411],[390,1664,1113],{"className":1665},[620]," is ",[390,1668,1670],{"className":1669},[393],[390,1671,1673],{"className":1672,"ariaHidden":398},[397],[390,1674,1676,1679],{"className":1675},[402],[390,1677],{"className":1678,"style":1035},[406],[390,1680,1682,1685],{"className":1681},[411],[390,1683,1042],{"className":1684},[411],[390,1686,1688],{"className":1687},[1046],[390,1689,1691],{"className":1690},[1050],[390,1692,1694],{"className":1693},[1054],[390,1695,1697],{"className":1696,"style":1035},[1058],[390,1698,1699,1702],{"style":1061},[390,1700],{"className":1701,"style":1066},[1065],[390,1703,1705],{"className":1704},[1070,1071,1072,1073],[390,1706,1708,1711,1714],{"className":1707},[411,1073],[390,1709,1021],{"className":1710,"style":1020},[411,412,1073],[390,1712,1398],{"className":1713},[1397,1073],[390,1715,1402],{"className":1716},[411,1073]," edges above ",[390,1719,1721],{"className":1720},[393],[390,1722,1724],{"className":1723,"ariaHidden":398},[397],[390,1725,1727,1730],{"className":1726},[402],[390,1728],{"className":1729,"style":407},[406],[390,1731,431],{"className":1732,"style":430},[411,412],"; applying the same jump to it\nclimbs another ",[390,1735,1737],{"className":1736},[393],[390,1738,1740],{"className":1739,"ariaHidden":398},[397],[390,1741,1743,1746],{"className":1742},[402],[390,1744],{"className":1745,"style":1035},[406],[390,1747,1749,1752],{"className":1748},[411],[390,1750,1042],{"className":1751},[411],[390,1753,1755],{"className":1754},[1046],[390,1756,1758],{"className":1757},[1050],[390,1759,1761],{"className":1760},[1054],[390,1762,1764],{"className":1763,"style":1035},[1058],[390,1765,1766,1769],{"style":1061},[390,1767],{"className":1768,"style":1066},[1065],[390,1770,1772],{"className":1771},[1070,1071,1072,1073],[390,1773,1775,1778,1781],{"className":1774},[411,1073],[390,1776,1021],{"className":1777,"style":1020},[411,412,1073],[390,1779,1398],{"className":1780},[1397,1073],[390,1782,1402],{"className":1783},[411,1073]," edges, for ",[390,1786,1788],{"className":1787},[393],[390,1789,1791,1846,1899],{"className":1790,"ariaHidden":398},[397],[390,1792,1794,1798,1836,1839,1843],{"className":1793},[402],[390,1795],{"className":1796,"style":1797},[406],"height:0.9324em;vertical-align:-0.0833em;",[390,1799,1801,1804],{"className":1800},[411],[390,1802,1042],{"className":1803},[411],[390,1805,1807],{"className":1806},[1046],[390,1808,1810],{"className":1809},[1050],[390,1811,1813],{"className":1812},[1054],[390,1814,1816],{"className":1815,"style":1035},[1058],[390,1817,1818,1821],{"style":1061},[390,1819],{"className":1820,"style":1066},[1065],[390,1822,1824],{"className":1823},[1070,1071,1072,1073],[390,1825,1827,1830,1833],{"className":1826},[411,1073],[390,1828,1021],{"className":1829,"style":1020},[411,412,1073],[390,1831,1398],{"className":1832},[1397,1073],[390,1834,1402],{"className":1835},[411,1073],[390,1837],{"className":1838,"style":1546},[612],[390,1840,1842],{"className":1841},[1397],"+",[390,1844],{"className":1845,"style":1546},[612],[390,1847,1849,1852,1890,1893,1896],{"className":1848},[402],[390,1850],{"className":1851,"style":1035},[406],[390,1853,1855,1858],{"className":1854},[411],[390,1856,1042],{"className":1857},[411],[390,1859,1861],{"className":1860},[1046],[390,1862,1864],{"className":1863},[1050],[390,1865,1867],{"className":1866},[1054],[390,1868,1870],{"className":1869,"style":1035},[1058],[390,1871,1872,1875],{"style":1061},[390,1873],{"className":1874,"style":1066},[1065],[390,1876,1878],{"className":1877},[1070,1071,1072,1073],[390,1879,1881,1884,1887],{"className":1880},[411,1073],[390,1882,1021],{"className":1883,"style":1020},[411,412,1073],[390,1885,1398],{"className":1886},[1397,1073],[390,1888,1402],{"className":1889},[411,1073],[390,1891],{"className":1892,"style":845},[612],[390,1894,850],{"className":1895},[849],[390,1897],{"className":1898,"style":845},[612],[390,1900,1902,1905],{"className":1901},[402],[390,1903],{"className":1904,"style":1035},[406],[390,1906,1908,1911],{"className":1907},[411],[390,1909,1042],{"className":1910},[411],[390,1912,1914],{"className":1913},[1046],[390,1915,1917],{"className":1916},[1050],[390,1918,1920],{"className":1919},[1054],[390,1921,1923],{"className":1922,"style":1035},[1058],[390,1924,1925,1928],{"style":1061},[390,1926],{"className":1927,"style":1066},[1065],[390,1929,1931],{"className":1930},[1070,1071,1072,1073],[390,1932,1021],{"className":1933,"style":1020},[411,412,1073]," total. ",[390,1936,1938],{"className":1937},[393],[390,1939,1941],{"className":1940,"ariaHidden":398},[397],[390,1942,1944,1948],{"className":1943},[402],[390,1945],{"className":1946,"style":1947},[406],"height:0.675em;",[390,1949,1953],{"className":1950},[1951,1952],"enclosing","qed",[390,1954,1957],{"className":1955},[411,1956],"amsrm","□",[381,1959,1960,1961,1976,1977,2011,2012,2107,2108,2142],{},"So column ",[390,1962,1964],{"className":1963},[393],[390,1965,1967],{"className":1966,"ariaHidden":398},[397],[390,1968,1970,1973],{"className":1969},[402],[390,1971],{"className":1972,"style":822},[406],[390,1974,1021],{"className":1975,"style":1020},[411,412]," of the table is computed entirely from column ",[390,1978,1980],{"className":1979},[393],[390,1981,1983,2002],{"className":1982,"ariaHidden":398},[397],[390,1984,1986,1990,1993,1996,1999],{"className":1985},[402],[390,1987],{"className":1988,"style":1989},[406],"height:0.7778em;vertical-align:-0.0833em;",[390,1991,1021],{"className":1992,"style":1020},[411,412],[390,1994],{"className":1995,"style":1546},[612],[390,1997,1398],{"className":1998},[1397],[390,2000],{"className":2001,"style":1546},[612],[390,2003,2005,2008],{"className":2004},[402],[390,2006],{"className":2007,"style":1448},[406],[390,2009,1402],{"className":2010},[411],", one pass per\npower of two. The number of columns is ",[390,2013,2015],{"className":2014},[393],[390,2016,2018,2038],{"className":2017,"ariaHidden":398},[397],[390,2019,2021,2024,2029,2032,2035],{"className":2020},[402],[390,2022],{"className":2023,"style":478},[406],[390,2025,2028],{"className":2026,"style":2027},[411,412],"margin-right:0.0715em;","K",[390,2030],{"className":2031,"style":845},[612],[390,2033,850],{"className":2034},[849],[390,2036],{"className":2037,"style":845},[612],[390,2039,2041,2044,2048,2097,2100,2103],{"className":2040},[402],[390,2042],{"className":2043,"style":586},[406],[390,2045,2047],{"className":2046},[599],"⌈",[390,2049,2051,2057],{"className":2050},[590],[390,2052,2054],{"className":2053},[590],[390,2055,873],{"className":2056,"style":872},[411,594],[390,2058,2060],{"className":2059},[1046],[390,2061,2064,2088],{"className":2062},[1050,2063],"vlist-t2",[390,2065,2067,2083],{"className":2066},[1054],[390,2068,2071],{"className":2069,"style":2070},[1058],"height:0.207em;",[390,2072,2074,2077],{"style":2073},"top:-2.4559em;margin-right:0.05em;",[390,2075],{"className":2076,"style":1066},[1065],[390,2078,2080],{"className":2079},[1070,1071,1072,1073],[390,2081,1042],{"className":2082},[411,1073],[390,2084,2087],{"className":2085},[2086],"vlist-s","​",[390,2089,2091],{"className":2090},[1054],[390,2092,2095],{"className":2093,"style":2094},[1058],"height:0.2441em;",[390,2096],{},[390,2098],{"className":2099,"style":613},[612],[390,2101,880],{"className":2102},[411,412],[390,2104,2106],{"className":2105},[620],"⌉",", since no node\nhas an ancestor more than ",[390,2109,2111],{"className":2110},[393],[390,2112,2114,2133],{"className":2113,"ariaHidden":398},[397],[390,2115,2117,2121,2124,2127,2130],{"className":2116},[402],[390,2118],{"className":2119,"style":2120},[406],"height:0.6667em;vertical-align:-0.0833em;",[390,2122,880],{"className":2123},[411,412],[390,2125],{"className":2126,"style":1546},[612],[390,2128,1398],{"className":2129},[1397],[390,2131],{"className":2132,"style":1546},[612],[390,2134,2136,2139],{"className":2135},[402],[390,2137],{"className":2138,"style":1448},[406],[390,2140,1402],{"className":2141},[411]," edges up.",[728,2144,2146],{"className":730,"code":2145,"language":732,"meta":376,"style":376},"caption: $\\textsc{Build-Up}(T)$ — preprocess $2^k$-th ancestors via doubling\nrun a DFS\u002FBFS from the root to fill $parent[\\cdot]$ and $depth[\\cdot]$\nfor each node $v$ do\n  $up[v][0] \\gets parent[v]$  \u002F\u002F root points to itself\nfor $k \\gets 1$ to $K$ do\n  for each node $v$ do\n    $up[v][k] \\gets up[\\,up[v][k-1]\\,][k-1]$\n",[734,2147,2148,2153,2158,2163,2168,2173,2178],{"__ignoreMap":376},[390,2149,2150],{"class":738,"line":6},[390,2151,2152],{},"caption: $\\textsc{Build-Up}(T)$ — preprocess $2^k$-th ancestors via doubling\n",[390,2154,2155],{"class":738,"line":18},[390,2156,2157],{},"run a DFS\u002FBFS from the root to fill $parent[\\cdot]$ and $depth[\\cdot]$\n",[390,2159,2160],{"class":738,"line":24},[390,2161,2162],{},"for each node $v$ do\n",[390,2164,2165],{"class":738,"line":73},[390,2166,2167],{},"  $up[v][0] \\gets parent[v]$  \u002F\u002F root points to itself\n",[390,2169,2170],{"class":738,"line":102},[390,2171,2172],{},"for $k \\gets 1$ to $K$ do\n",[390,2174,2175],{"class":738,"line":108},[390,2176,2177],{},"  for each node $v$ do\n",[390,2179,2180],{"class":738,"line":116},[390,2181,2182],{},"    $up[v][k] \\gets up[\\,up[v][k-1]\\,][k-1]$\n",[381,2184,2185,2186,2219,2220,2244,2245,2284,2285,2324],{},"The table has ",[390,2187,2189],{"className":2188},[393],[390,2190,2192],{"className":2191,"ariaHidden":398},[397],[390,2193,2195,2198,2201,2204,2207,2213,2216],{"className":2194},[402],[390,2196],{"className":2197,"style":586},[406],[390,2199,880],{"className":2200},[411,412],[390,2202,600],{"className":2203},[599],[390,2205,2028],{"className":2206,"style":2027},[411,412],[390,2208,2210],{"className":2209},[411],[390,2211,1842],{"className":2212},[411],[390,2214,1402],{"className":2215},[411],[390,2217,621],{"className":2218},[620]," entries and each costs ",[390,2221,2223],{"className":2222},[393],[390,2224,2226],{"className":2225,"ariaHidden":398},[397],[390,2227,2229,2232,2235,2238,2241],{"className":2228},[402],[390,2230],{"className":2231,"style":586},[406],[390,2233,798],{"className":2234,"style":463},[411,412],[390,2236,600],{"className":2237},[599],[390,2239,1402],{"className":2240},[411],[390,2242,621],{"className":2243},[620],", so preprocessing is\n",[390,2246,2248],{"className":2247},[393],[390,2249,2251],{"className":2250,"ariaHidden":398},[397],[390,2252,2254,2257,2260,2263,2266,2269,2275,2278,2281],{"className":2253},[402],[390,2255],{"className":2256,"style":586},[406],[390,2258,798],{"className":2259,"style":463},[411,412],[390,2261,600],{"className":2262},[599],[390,2264,880],{"className":2265},[411,412],[390,2267],{"className":2268,"style":613},[612],[390,2270,2272],{"className":2271},[590],[390,2273,873],{"className":2274,"style":872},[411,594],[390,2276],{"className":2277,"style":613},[612],[390,2279,880],{"className":2280},[411,412],[390,2282,621],{"className":2283},[620]," time and ",[390,2286,2288],{"className":2287},[393],[390,2289,2291],{"className":2290,"ariaHidden":398},[397],[390,2292,2294,2297,2300,2303,2306,2309,2315,2318,2321],{"className":2293},[402],[390,2295],{"className":2296,"style":586},[406],[390,2298,798],{"className":2299,"style":463},[411,412],[390,2301,600],{"className":2302},[599],[390,2304,880],{"className":2305},[411,412],[390,2307],{"className":2308,"style":613},[612],[390,2310,2312],{"className":2311},[590],[390,2313,873],{"className":2314,"style":872},[411,594],[390,2316],{"className":2317,"style":613},[612],[390,2319,880],{"className":2320},[411,412],[390,2322,621],{"className":2323},[620]," space.",[2326,2327,2331,2480],"figure",{"className":2328},[2329,2330],"tikz-figure","tikz-diagram-rendered",[2332,2333,2338],"svg",{"xmlns":2334,"width":2335,"height":2336,"viewBox":2337},"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","187.102","186.837","-75 -75 140.327 140.128",[2339,2340,2343,2348,2357,2360,2367,2370,2377,2380,2407,2428],"g",{"stroke":2341,"style":2342},"currentColor","stroke-miterlimit:10;stroke-width:.4",[2344,2345],"path",{"fill":2346,"d":2347},"none","M28.215-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",[2339,2349,2351],{"transform":2350},"translate(-2.408 1.937)",[2344,2352],{"d":2353,"fill":2341,"stroke":2341,"className":2354,"style":2356},"M19.262-63.158Q19.262-63.356 19.315-63.613Q19.368-63.870 19.429-64.063Q19.491-64.257 19.601-64.540Q19.711-64.823 19.794-65.039Q19.913-65.324 19.913-65.557Q19.913-65.676 19.867-65.753Q19.820-65.830 19.715-65.830Q19.363-65.830 19.128-65.469Q18.893-65.109 18.788-64.678Q18.770-64.595 18.695-64.595L18.590-64.595Q18.542-64.595 18.520-64.634Q18.498-64.674 18.498-64.714Q18.586-65.056 18.746-65.362Q18.906-65.667 19.157-65.878Q19.407-66.089 19.733-66.089Q20.071-66.089 20.302-65.883Q20.532-65.676 20.532-65.333Q20.532-65.153 20.471-64.999Q20.379-64.753 20.262-64.450Q20.146-64.147 20.075-63.920Q20.005-63.694 19.959-63.474Q19.913-63.255 19.913-63.039Q19.913-62.696 20.078-62.486Q20.242-62.275 20.576-62.275Q21.231-62.275 21.710-63.255Q21.855-63.536 22-63.953Q22.145-64.371 22.145-64.630Q22.145-64.885 22.066-65.028Q21.987-65.171 21.835-65.351Q21.684-65.531 21.684-65.623Q21.684-65.803 21.831-65.951Q21.978-66.098 22.163-66.098Q22.387-66.098 22.486-65.891Q22.585-65.685 22.585-65.434Q22.585-65.012 22.444-64.435Q22.303-63.857 22.035-63.296Q21.767-62.736 21.391-62.373Q21.016-62.011 20.559-62.011Q19.974-62.011 19.618-62.297Q19.262-62.582 19.262-63.158",[2355],"tikz-text","stroke-width:0.270",[2344,2358],{"fill":2346,"d":2359},"M28.215-33.659c0-5.5-4.459-9.958-9.959-9.958S8.298-39.16 8.298-33.66s4.458 9.959 9.958 9.959 9.959-4.459 9.959-9.959ZM28.215-5.206c0-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",[2339,2361,2363],{"transform":2362},"translate(-4.075 58.843)",[2344,2364],{"d":2365,"fill":2341,"stroke":2341,"className":2366,"style":2356},"M18.994-62.283Q18.994-62.336 19.003-62.371L19.671-65.039Q19.724-65.237 19.724-65.434Q19.724-65.830 19.460-65.830Q19.174-65.830 19.040-65.507Q18.906-65.184 18.788-64.678Q18.770-64.595 18.695-64.595L18.590-64.595Q18.542-64.595 18.520-64.634Q18.498-64.674 18.498-64.714Q18.660-65.333 18.860-65.711Q19.060-66.089 19.482-66.089Q19.702-66.089 19.906-65.995Q20.110-65.900 20.240-65.727Q20.370-65.553 20.370-65.333Q20.647-65.685 21.009-65.887Q21.372-66.089 21.785-66.089Q22.211-66.089 22.538-65.869Q22.866-65.650 22.866-65.245Q23.046-65.491 23.277-65.683Q23.507-65.874 23.778-65.981Q24.048-66.089 24.347-66.089Q24.843-66.089 25.140-65.836Q25.437-65.584 25.437-65.100Q25.437-64.727 25.276-64.232Q25.116-63.738 24.861-63.066Q24.747-62.771 24.747-62.543Q24.747-62.275 24.936-62.275Q25.287-62.275 25.529-62.644Q25.771-63.013 25.872-63.426Q25.881-63.457 25.905-63.481Q25.929-63.505 25.960-63.505L26.069-63.505Q26.113-63.505 26.135-63.472Q26.157-63.439 26.157-63.391Q26.030-62.868 25.707-62.439Q25.384-62.011 24.927-62.011Q24.593-62.011 24.358-62.224Q24.123-62.437 24.123-62.771Q24.123-62.956 24.189-63.101Q24.448-63.764 24.619-64.305Q24.791-64.845 24.791-65.237Q24.791-65.491 24.681-65.661Q24.571-65.830 24.329-65.830Q23.833-65.830 23.464-65.516Q23.094-65.201 22.826-64.687Q22.822-64.670 22.820-64.654Q22.818-64.639 22.809-64.612L22.242-62.336Q22.207-62.195 22.095-62.103Q21.983-62.011 21.846-62.011Q21.719-62.011 21.640-62.086Q21.561-62.160 21.561-62.283Q21.561-62.336 21.569-62.371L22.136-64.652Q22.224-65.048 22.224-65.237Q22.224-65.390 22.183-65.527Q22.141-65.663 22.040-65.746Q21.939-65.830 21.767-65.830Q21.271-65.830 20.902-65.518Q20.532-65.206 20.264-64.696L19.680-62.336Q19.649-62.200 19.533-62.105Q19.416-62.011 19.280-62.011Q19.161-62.011 19.078-62.086Q18.994-62.160 18.994-62.283",[2355],[2344,2368],{"fill":2346,"d":2369},"M28.215 23.247c0-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.958ZM28.215 51.7c0-5.5-4.459-9.959-9.959-9.959s-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",[2339,2371,2373],{"transform":2372},"translate(-3.436 115.748)",[2344,2374],{"d":2375,"fill":2341,"stroke":2341,"className":2376,"style":2356},"M19.262-63.175Q19.262-63.448 19.341-63.753Q19.421-64.059 19.548-64.393Q19.675-64.727 19.794-65.039Q19.913-65.324 19.913-65.557Q19.913-65.676 19.867-65.753Q19.820-65.830 19.715-65.830Q19.363-65.830 19.128-65.469Q18.893-65.109 18.788-64.678Q18.770-64.595 18.695-64.595L18.590-64.595Q18.542-64.595 18.520-64.634Q18.498-64.674 18.498-64.714Q18.586-65.056 18.746-65.362Q18.906-65.667 19.157-65.878Q19.407-66.089 19.733-66.089Q20.071-66.089 20.302-65.880Q20.532-65.672 20.532-65.333Q20.532-65.153 20.471-64.999Q20.466-64.982 20.328-64.621Q20.190-64.261 20.108-64.015Q20.027-63.769 19.974-63.525Q19.922-63.281 19.922-63.066Q19.922-62.701 20.108-62.488Q20.295-62.275 20.651-62.275Q21.134-62.275 21.442-62.987L21.442-63.158Q21.442-63.444 21.504-63.685L22-65.676Q22.035-65.817 22.150-65.904Q22.264-65.992 22.404-65.992Q22.527-65.992 22.607-65.918Q22.686-65.843 22.686-65.720Q22.686-65.667 22.677-65.641L22.180-63.650Q22.088-63.215 22.088-63.039Q22.088-62.705 22.255-62.490Q22.422-62.275 22.756-62.275Q23.138-62.275 23.400-62.571Q23.661-62.868 23.837-63.307Q23.973-63.659 24.085-64.035Q24.197-64.410 24.197-64.630Q24.197-64.885 24.118-65.028Q24.039-65.171 23.888-65.351Q23.736-65.531 23.736-65.623Q23.736-65.808 23.885-65.953Q24.035-66.098 24.215-66.098Q24.439-66.098 24.538-65.891Q24.637-65.685 24.637-65.425Q24.637-65.153 24.556-64.758Q24.474-64.362 24.353-63.960Q24.233-63.558 24.140-63.338Q24-62.987 23.813-62.692Q23.626-62.398 23.358-62.204Q23.090-62.011 22.738-62.011Q22.308-62.011 22.048-62.134Q21.789-62.257 21.561-62.600Q21.187-62.011 20.633-62.011Q20.238-62.011 19.930-62.132Q19.623-62.253 19.443-62.514Q19.262-62.776 19.262-63.175",[2355],[2344,2378],{"fill":2346,"d":2379},"M18.256-51.953v8.136m0 20.317v8.135m0 20.317v8.136m0 20.317v8.136",[2339,2381,2384,2387,2390],{"fill":2382,"stroke":2382,"style":2383},"var(--tk-accent)","stroke-width:.8",[2344,2385],{"fill":2346,"d":2386},"M27.054-57.032C42.84-47.917 42.84-19.4 29.305-11.585",[2344,2388],{"stroke":2346,"d":2389},"m27.054-10.285 4.642-.279-2.39-1.021.31-2.581",[2339,2391,2392,2400],{"fill":2382,"stroke":2346},[2339,2393,2395],{"transform":2394},"translate(29.634 31.798)",[2344,2396],{"d":2397,"fill":2382,"stroke":2382,"className":2398,"style":2399},"M21.842-62.112L18.682-62.112L18.682-62.319Q18.682-62.346 18.705-62.378L20.057-63.776Q20.436-64.163 20.684-64.452Q20.932-64.741 21.106-65.098Q21.279-65.456 21.279-65.846Q21.279-66.194 21.147-66.487Q21.014-66.780 20.760-66.958Q20.506-67.135 20.151-67.135Q19.791-67.135 19.500-66.940Q19.209-66.745 19.065-66.417L19.119-66.417Q19.303-66.417 19.428-66.296Q19.553-66.174 19.553-65.983Q19.553-65.803 19.428-65.674Q19.303-65.546 19.119-65.546Q18.940-65.546 18.811-65.674Q18.682-65.803 18.682-65.983Q18.682-66.385 18.902-66.721Q19.123-67.057 19.488-67.245Q19.854-67.432 20.256-67.432Q20.736-67.432 21.152-67.245Q21.569-67.057 21.820-66.696Q22.072-66.335 22.072-65.846Q22.072-65.487 21.918-65.184Q21.764-64.882 21.512-64.622Q21.260-64.362 20.910-64.077Q20.561-63.792 20.393-63.639L19.463-62.800L20.178-62.800Q21.553-62.800 21.592-62.839Q21.662-62.917 21.705-63.102Q21.748-63.288 21.791-63.577L22.072-63.577",[2355],"stroke-width:0.240",[2339,2401,2402],{"transform":2394},[2344,2403],{"d":2404,"fill":2382,"stroke":2382,"className":2405,"style":2406},"M25.547-64.935L23.256-64.935L23.256-65.193Q24.132-65.193 24.132-65.366L24.132-68.445Q23.939-68.357 23.707-68.320Q23.476-68.284 23.221-68.284L23.221-68.541Q23.599-68.541 23.920-68.626Q24.240-68.711 24.469-68.925L24.589-68.925Q24.621-68.925 24.646-68.902Q24.671-68.878 24.671-68.840L24.671-65.366Q24.671-65.193 25.547-65.193",[2355],"stroke-width:0.180",[2339,2408,2409,2412,2415],{"fill":2382,"stroke":2382,"style":2383},[2344,2410],{"fill":2346,"d":2411},"M27.054-.127C42.84 8.988 42.84 37.505 29.305 45.32",[2344,2413],{"stroke":2346,"d":2414},"m27.054 46.62 4.642-.278-2.39-1.022.31-2.58",[2339,2416,2417,2423],{"fill":2382,"stroke":2346},[2339,2418,2420],{"transform":2419},"translate(29.634 88.703)",[2344,2421],{"d":2397,"fill":2382,"stroke":2382,"className":2422,"style":2399},[2355],[2339,2424,2425],{"transform":2419},[2344,2426],{"d":2404,"fill":2382,"stroke":2382,"className":2427,"style":2406},[2355],[2339,2429,2430,2433,2436],{"style":2383},[2344,2431],{"fill":2346,"d":2432},"M9.935-56.285c-32.634 22.85-32.634 79.307-2.13 100.667",[2344,2434],{"stroke":2346,"d":2435},"m9.935 45.873-2.214-4.09.084 2.599-2.47.809",[2339,2437,2438,2444,2450,2456,2462,2468,2474],{"stroke":2346},[2339,2439,2441],{"transform":2440},"translate(-83.486 59.25)",[2344,2442],{"d":2397,"fill":2341,"stroke":2341,"className":2443,"style":2399},[2355],[2339,2445,2446],{"transform":2440},[2344,2447],{"d":2448,"fill":2341,"stroke":2341,"className":2449,"style":2406},"M25.547-64.935L22.937-64.935L22.937-65.120Q22.943-65.143 22.963-65.169L24.114-66.224Q24.454-66.535 24.634-66.721Q24.815-66.907 24.960-67.167Q25.105-67.428 25.105-67.724Q25.105-67.997 24.979-68.212Q24.853-68.427 24.633-68.547Q24.413-68.667 24.138-68.667Q23.962-68.667 23.792-68.610Q23.622-68.553 23.490-68.446Q23.359-68.339 23.279-68.181Q23.367-68.181 23.445-68.137Q23.523-68.093 23.567-68.017Q23.610-67.941 23.610-67.844Q23.610-67.704 23.514-67.607Q23.417-67.510 23.274-67.510Q23.136-67.510 23.036-67.610Q22.937-67.709 22.937-67.844Q22.937-68.169 23.127-68.417Q23.318-68.664 23.621-68.795Q23.924-68.925 24.240-68.925Q24.621-68.925 24.964-68.790Q25.307-68.656 25.521-68.383Q25.735-68.111 25.735-67.724Q25.735-67.449 25.610-67.222Q25.485-66.995 25.305-66.823Q25.125-66.652 24.800-66.412Q24.475-66.171 24.390-66.104L23.634-65.500L24.167-65.500Q24.656-65.500 24.987-65.508Q25.319-65.515 25.333-65.530Q25.392-65.600 25.424-65.735Q25.456-65.870 25.488-66.081L25.735-66.081",[2355],[2339,2451,2452],{"transform":2440},[2344,2453],{"d":2454,"fill":2341,"stroke":2341,"className":2455,"style":2399},"M34.995-63.089L29.682-63.089Q29.604-63.096 29.555-63.145Q29.507-63.194 29.507-63.272Q29.507-63.342 29.554-63.393Q29.600-63.444 29.682-63.456L34.995-63.456Q35.069-63.444 35.116-63.393Q35.163-63.342 35.163-63.272Q35.163-63.194 35.114-63.145Q35.065-63.096 34.995-63.089M34.995-64.776L29.682-64.776Q29.604-64.784 29.555-64.833Q29.507-64.882 29.507-64.960Q29.507-65.030 29.554-65.081Q29.600-65.132 29.682-65.143L34.995-65.143Q35.069-65.132 35.116-65.081Q35.163-65.030 35.163-64.960Q35.163-64.882 35.114-64.833Q35.065-64.784 34.995-64.776",[2355],[2339,2457,2458],{"transform":2440},[2344,2459],{"d":2460,"fill":2341,"stroke":2341,"className":2461,"style":2399},"M38.937-63.034Q38.937-63.284 39.011-63.571Q39.085-63.858 39.222-64.210Q39.359-64.561 39.421-64.729Q39.511-64.952 39.511-65.135Q39.511-65.385 39.343-65.385Q39.027-65.385 38.818-65.079Q38.609-64.772 38.503-64.385Q38.491-64.311 38.421-64.311L38.319-64.311Q38.284-64.311 38.257-64.346Q38.230-64.382 38.230-64.409L38.230-64.440Q38.355-64.901 38.652-65.270Q38.948-65.639 39.359-65.639Q39.554-65.639 39.728-65.555Q39.902-65.471 40.003-65.319Q40.105-65.167 40.105-64.960Q40.105-64.807 40.046-64.671Q39.956-64.440 39.855-64.174Q39.753-63.909 39.696-63.727Q39.640-63.546 39.595-63.331Q39.550-63.116 39.550-62.921Q39.550-62.647 39.673-62.467Q39.796-62.288 40.054-62.288Q40.323-62.288 40.632-62.516Q40.941-62.745 40.991-62.999L41.558-65.272Q41.597-65.397 41.700-65.479Q41.804-65.561 41.929-65.561Q42.038-65.561 42.118-65.487Q42.198-65.413 42.198-65.303Q42.198-65.280 42.183-65.217L41.616-62.944Q41.612-62.905 41.599-62.844Q41.585-62.784 41.579-62.733Q41.573-62.682 41.573-62.647Q41.573-62.288 41.823-62.288Q41.964-62.288 42.066-62.395Q42.167-62.503 42.232-62.657Q42.296-62.811 42.345-63.001Q42.394-63.190 42.413-63.288Q42.448-63.358 42.503-63.358L42.609-63.358Q42.648-63.358 42.671-63.329Q42.694-63.300 42.694-63.264Q42.694-63.249 42.687-63.233Q42.616-62.936 42.519-62.678Q42.421-62.421 42.245-62.227Q42.069-62.034 41.808-62.034Q41.542-62.034 41.319-62.167Q41.097-62.300 41.007-62.538Q40.819-62.311 40.564-62.173Q40.308-62.034 40.038-62.034Q39.714-62.034 39.464-62.143Q39.214-62.253 39.075-62.477Q38.937-62.702 38.937-63.034M44.417-60.561L42.816-60.561Q42.780-60.561 42.747-60.602Q42.714-60.643 42.714-60.678L42.745-60.784Q42.777-60.846 42.831-60.854Q43.023-60.854 43.107-60.870Q43.191-60.885 43.243-60.952Q43.296-61.018 43.335-61.159L44.226-64.729Q44.265-64.885 44.265-65.022Q44.265-65.171 44.212-65.278Q44.159-65.385 44.027-65.385Q43.847-65.385 43.728-65.216Q43.609-65.046 43.552-64.860Q43.495-64.674 43.425-64.385Q43.413-64.311 43.343-64.311L43.241-64.311Q43.206-64.311 43.179-64.346Q43.152-64.382 43.152-64.409L43.152-64.440Q43.237-64.772 43.331-65.014Q43.425-65.257 43.601-65.448Q43.777-65.639 44.042-65.639Q44.323-65.639 44.554-65.495Q44.784-65.350 44.851-65.096Q45.370-65.639 45.929-65.639Q46.464-65.639 46.784-65.255Q47.105-64.870 47.105-64.327Q47.105-63.803 46.823-63.264Q46.542-62.725 46.075-62.380Q45.609-62.034 45.073-62.034Q44.835-62.034 44.634-62.151Q44.433-62.268 44.304-62.479L43.960-61.104Q43.948-61.065 43.929-60.944Q43.929-60.854 44.433-60.854Q44.538-60.823 44.538-60.729L44.503-60.624Q44.472-60.569 44.417-60.561M44.859-64.678L44.425-62.952Q44.484-62.678 44.653-62.483Q44.823-62.288 45.089-62.288Q45.425-62.288 45.704-62.579Q45.984-62.870 46.120-63.225Q46.245-63.518 46.347-63.952Q46.448-64.385 46.448-64.663Q46.448-64.948 46.316-65.167Q46.183-65.385 45.913-65.385Q45.702-65.385 45.507-65.284Q45.312-65.182 45.152-65.026Q44.991-64.870 44.859-64.678",[2355],[2339,2463,2464],{"transform":2440},[2344,2465],{"d":2466,"fill":2341,"stroke":2341,"className":2467,"style":2399},"M49.375-60.112L48.199-60.112L48.199-68.112L49.375-68.112L49.375-67.745L48.566-67.745L48.566-60.479L49.375-60.479",[2355],[2339,2469,2470],{"transform":2440},[2344,2471],{"d":2472,"fill":2341,"stroke":2341,"className":2473,"style":2399},"M50.505-63.065Q50.505-63.237 50.548-63.448Q50.591-63.659 50.652-63.846Q50.713-64.034 50.810-64.286Q50.908-64.538 50.982-64.729Q51.072-64.952 51.072-65.135Q51.072-65.385 50.904-65.385Q50.588-65.385 50.379-65.079Q50.170-64.772 50.064-64.385Q50.052-64.311 49.982-64.311L49.880-64.311Q49.845-64.311 49.818-64.346Q49.791-64.382 49.791-64.409L49.791-64.440Q49.916-64.901 50.213-65.270Q50.509-65.639 50.920-65.639Q51.115-65.639 51.289-65.555Q51.463-65.471 51.564-65.319Q51.666-65.167 51.666-64.960Q51.666-64.807 51.607-64.671Q51.513-64.428 51.388-64.100Q51.263-63.772 51.191-63.493Q51.119-63.214 51.119-62.960Q51.119-62.651 51.273-62.469Q51.427-62.288 51.728-62.288Q52.123-62.288 52.505-62.760Q52.634-62.928 52.781-63.229Q52.927-63.530 53.023-63.829Q53.119-64.128 53.119-64.335Q53.119-64.561 53.045-64.680Q52.970-64.799 52.834-64.954Q52.697-65.108 52.697-65.210Q52.697-65.382 52.838-65.514Q52.978-65.647 53.134-65.647Q53.349-65.647 53.443-65.456Q53.537-65.264 53.537-65.034Q53.537-64.530 53.308-63.809Q53.080-63.089 52.660-62.561Q52.240-62.034 51.713-62.034Q51.459-62.034 51.238-62.092Q51.017-62.151 50.855-62.276Q50.693-62.401 50.599-62.602Q50.505-62.803 50.505-63.065",[2355],[2339,2475,2476],{"transform":2440},[2344,2477],{"d":2478,"fill":2341,"stroke":2341,"className":2479,"style":2399},"M55.353-60.112L54.178-60.112L54.178-60.479L54.986-60.479L54.986-67.745L54.178-67.745L54.178-68.112L55.353-68.112L55.353-60.112M58.521-60.112L57.346-60.112L57.346-68.112L58.521-68.112L58.521-67.745L57.713-67.745L57.713-60.479L58.521-60.479L58.521-60.112M62.299-62.112L59.139-62.112L59.139-62.319Q59.139-62.346 59.162-62.378L60.514-63.776Q60.892-64.163 61.140-64.452Q61.389-64.741 61.562-65.098Q61.736-65.456 61.736-65.846Q61.736-66.194 61.603-66.487Q61.471-66.780 61.217-66.958Q60.963-67.135 60.607-67.135Q60.248-67.135 59.957-66.940Q59.666-66.745 59.521-66.417L59.576-66.417Q59.760-66.417 59.885-66.296Q60.010-66.174 60.010-65.983Q60.010-65.803 59.885-65.674Q59.760-65.546 59.576-65.546Q59.396-65.546 59.267-65.674Q59.139-65.803 59.139-65.983Q59.139-66.385 59.359-66.721Q59.580-67.057 59.945-67.245Q60.310-67.432 60.713-67.432Q61.193-67.432 61.609-67.245Q62.025-67.057 62.277-66.696Q62.529-66.335 62.529-65.846Q62.529-65.487 62.375-65.184Q62.221-64.882 61.969-64.622Q61.717-64.362 61.367-64.077Q61.017-63.792 60.849-63.639L59.920-62.800L60.635-62.800Q62.010-62.800 62.049-62.839Q62.119-62.917 62.162-63.102Q62.205-63.288 62.248-63.577L62.529-63.577L62.299-62.112M64.318-60.112L63.142-60.112L63.142-60.479L63.951-60.479L63.951-67.745L63.142-67.745L63.142-68.112L64.318-68.112",[2355],[2481,2482,2485,2486,2522,2523,2539,2540,2577,2578,2593],"figcaption",{"className":2483},[2484],"tikz-cap","doubling identity: ",[390,2487,2489],{"className":2488},[393],[390,2490,2492],{"className":2491,"ariaHidden":398},[397],[390,2493,2495,2498,2501,2504,2507,2510,2513,2516,2519],{"className":2494},[402],[390,2496],{"className":2497,"style":586},[406],[390,2499,413],{"className":2500},[411,412],[390,2502,381],{"className":2503},[411,412],[390,2505,1106],{"className":2506},[599],[390,2508,431],{"className":2509,"style":430},[411,412],[390,2511,1113],{"className":2512},[620],[390,2514,1106],{"className":2515},[599],[390,2517,1042],{"className":2518},[411],[390,2520,1113],{"className":2521},[620]," (a ",[390,2524,2526],{"className":2525},[393],[390,2527,2529],{"className":2528,"ariaHidden":398},[397],[390,2530,2532,2535],{"className":2531},[402],[390,2533],{"className":2534,"style":1448},[406],[390,2536,2538],{"className":2537},[411],"4","-edge climb) is two ",[390,2541,2543],{"className":2542},[393],[390,2544,2546],{"className":2545,"ariaHidden":398},[397],[390,2547,2549,2552,2555,2558,2561,2565,2568,2571,2574],{"className":2548},[402],[390,2550],{"className":2551,"style":586},[406],[390,2553,413],{"className":2554},[411,412],[390,2556,381],{"className":2557},[411,412],[390,2559,1106],{"className":2560},[599],[390,2562,2564],{"className":2563},[411],"⋅",[390,2566,1113],{"className":2567},[620],[390,2569,1106],{"className":2570},[599],[390,2572,1402],{"className":2573},[411],[390,2575,1113],{"className":2576},[620]," jumps of ",[390,2579,2581],{"className":2580},[393],[390,2582,2584],{"className":2583,"ariaHidden":398},[397],[390,2585,2587,2590],{"className":2586},[402],[390,2588],{"className":2589,"style":1448},[406],[390,2591,1042],{"className":2592},[411]," edges each",[2595,2596,2598,2613,2614],"h3",{"id":2597},"k-th-ancestor-in-ologn",[390,2599,2601],{"className":2600},[393],[390,2602,2604],{"className":2603,"ariaHidden":398},[397],[390,2605,2607,2610],{"className":2606},[402],[390,2608],{"className":2609,"style":822},[406],[390,2611,1021],{"className":2612,"style":1020},[411,412],"-th ancestor in ",[390,2615,2617],{"className":2616},[393],[390,2618,2620],{"className":2619,"ariaHidden":398},[397],[390,2621,2623,2626,2629,2632,2638,2641,2644],{"className":2622},[402],[390,2624],{"className":2625,"style":586},[406],[390,2627,798],{"className":2628,"style":463},[411,412],[390,2630,600],{"className":2631},[599],[390,2633,2635],{"className":2634},[590],[390,2636,873],{"className":2637,"style":872},[411,594],[390,2639],{"className":2640,"style":613},[612],[390,2642,880],{"className":2643},[411,412],[390,2645,621],{"className":2646},[620],[381,2648,2649,2650,2665,2666,2681,2682,2806,2807,437],{},"Any non-negative integer ",[390,2651,2653],{"className":2652},[393],[390,2654,2656],{"className":2655,"ariaHidden":398},[397],[390,2657,2659,2662],{"className":2658},[402],[390,2660],{"className":2661,"style":822},[406],[390,2663,1021],{"className":2664,"style":1020},[411,412]," has a unique binary expansion, so the climb of ",[390,2667,2669],{"className":2668},[393],[390,2670,2672],{"className":2671,"ariaHidden":398},[397],[390,2673,2675,2678],{"className":2674},[402],[390,2676],{"className":2677,"style":822},[406],[390,2679,1021],{"className":2680,"style":1020},[411,412],"\nedges decomposes into jumps of size ",[390,2683,2685],{"className":2684},[393],[390,2686,2688],{"className":2687,"ariaHidden":398},[397],[390,2689,2691,2695,2725,2728,2731,2760,2763,2766,2795,2798,2801],{"className":2690},[402],[390,2692],{"className":2693,"style":2694},[406],"height:1.0085em;vertical-align:-0.1944em;",[390,2696,2698,2701],{"className":2697},[411],[390,2699,1042],{"className":2700},[411],[390,2702,2704],{"className":2703},[1046],[390,2705,2707],{"className":2706},[1050],[390,2708,2710],{"className":2709},[1054],[390,2711,2714],{"className":2712,"style":2713},[1058],"height:0.8141em;",[390,2715,2716,2719],{"style":1061},[390,2717],{"className":2718,"style":1066},[1065],[390,2720,2722],{"className":2721},[1070,1071,1072,1073],[390,2723,1257],{"className":2724},[411,1073],[390,2726,608],{"className":2727},[607],[390,2729],{"className":2730,"style":613},[612],[390,2732,2734,2737],{"className":2733},[411],[390,2735,1042],{"className":2736},[411],[390,2738,2740],{"className":2739},[1046],[390,2741,2743],{"className":2742},[1050],[390,2744,2746],{"className":2745},[1054],[390,2747,2749],{"className":2748,"style":2713},[1058],[390,2750,2751,2754],{"style":1061},[390,2752],{"className":2753,"style":1066},[1065],[390,2755,2757],{"className":2756},[1070,1071,1072,1073],[390,2758,1402],{"className":2759},[411,1073],[390,2761,608],{"className":2762},[607],[390,2764],{"className":2765,"style":613},[612],[390,2767,2769,2772],{"className":2768},[411],[390,2770,1042],{"className":2771},[411],[390,2773,2775],{"className":2774},[1046],[390,2776,2778],{"className":2777},[1050],[390,2779,2781],{"className":2780},[1054],[390,2782,2784],{"className":2783,"style":2713},[1058],[390,2785,2786,2789],{"style":1061},[390,2787],{"className":2788,"style":1066},[1065],[390,2790,2792],{"className":2791},[1070,1071,1072,1073],[390,2793,1042],{"className":2794},[411,1073],[390,2796,608],{"className":2797},[607],[390,2799],{"className":2800,"style":613},[612],[390,2802,2805],{"className":2803},[2804],"minner","…",", one jump per set bit.\nTake each set bit from low to high and follow the matching column of ",[734,2808,2809],{},"up",[728,2811,2813],{"className":730,"code":2812,"language":732,"meta":376,"style":376},"caption: $\\textsc{Kth-Ancestor}(v, k)$ — jump by each 1-bit of $k$\nfor $j \\gets 0$ to $K$ do\n  if $k$ has bit $j$ set then\n    $v \\gets up[v][j]$\n    if $v = \\text{nil}$ then return nil  \u002F\u002F ran off the root\nreturn $v$\n",[734,2814,2815,2820,2825,2830,2835,2840],{"__ignoreMap":376},[390,2816,2817],{"class":738,"line":6},[390,2818,2819],{},"caption: $\\textsc{Kth-Ancestor}(v, k)$ — jump by each 1-bit of $k$\n",[390,2821,2822],{"class":738,"line":18},[390,2823,2824],{},"for $j \\gets 0$ to $K$ do\n",[390,2826,2827],{"class":738,"line":24},[390,2828,2829],{},"  if $k$ has bit $j$ set then\n",[390,2831,2832],{"class":738,"line":73},[390,2833,2834],{},"    $v \\gets up[v][j]$\n",[390,2836,2837],{"class":738,"line":102},[390,2838,2839],{},"    if $v = \\text{nil}$ then return nil  \u002F\u002F ran off the root\n",[390,2841,2842],{"class":738,"line":108},[390,2843,2844],{},"return $v$\n",[381,2846,2847,2848,2882,2883,2916,2917,2920],{},"At most ",[390,2849,2851],{"className":2850},[393],[390,2852,2854,2873],{"className":2853,"ariaHidden":398},[397],[390,2855,2857,2861,2864,2867,2870],{"className":2856},[402],[390,2858],{"className":2859,"style":2860},[406],"height:0.7667em;vertical-align:-0.0833em;",[390,2862,2028],{"className":2863,"style":2027},[411,412],[390,2865],{"className":2866,"style":1546},[612],[390,2868,1842],{"className":2869},[1397],[390,2871],{"className":2872,"style":1546},[612],[390,2874,2876,2879],{"className":2875},[402],[390,2877],{"className":2878,"style":1448},[406],[390,2880,1402],{"className":2881},[411]," bits are set, so this is ",[390,2884,2886],{"className":2885},[393],[390,2887,2889],{"className":2888,"ariaHidden":398},[397],[390,2890,2892,2895,2898,2901,2907,2910,2913],{"className":2891},[402],[390,2893],{"className":2894,"style":586},[406],[390,2896,798],{"className":2897,"style":463},[411,412],[390,2899,600],{"className":2900},[599],[390,2902,2904],{"className":2903},[590],[390,2905,873],{"className":2906,"style":872},[411,594],[390,2908],{"className":2909,"style":613},[612],[390,2911,880],{"className":2912},[411,412],[390,2914,621],{"className":2915},[620],". The order of the jumps does\nnot matter for the ",[385,2918,2919],{},"destination"," (they compose to the same total climb), but\nprocessing low bits first keeps the running node well-defined at each step.",[2326,2922,2924,3015],{"className":2923},[2329,2330],[2332,2925,2929],{"xmlns":2334,"width":2926,"height":2927,"viewBox":2928},"181.087","215.290","-75 -75 135.815 161.467",[2339,2930,2931,2934,2940,2943,2966,2988],{"stroke":2341,"style":2342},[2344,2932],{"fill":2346,"d":2933},"M-5.91-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",[2339,2935,2936],{"transform":2350},[2344,2937],{"d":2938,"fill":2341,"stroke":2341,"className":2939,"style":2356},"M-14.862-63.158Q-14.862-63.356-14.809-63.613Q-14.756-63.870-14.695-64.063Q-14.633-64.257-14.523-64.540Q-14.413-64.823-14.330-65.039Q-14.211-65.324-14.211-65.557Q-14.211-65.676-14.257-65.753Q-14.304-65.830-14.409-65.830Q-14.761-65.830-14.996-65.469Q-15.231-65.109-15.336-64.678Q-15.354-64.595-15.429-64.595L-15.534-64.595Q-15.582-64.595-15.604-64.634Q-15.626-64.674-15.626-64.714Q-15.538-65.056-15.378-65.362Q-15.218-65.667-14.967-65.878Q-14.717-66.089-14.391-66.089Q-14.053-66.089-13.822-65.883Q-13.592-65.676-13.592-65.333Q-13.592-65.153-13.653-64.999Q-13.745-64.753-13.862-64.450Q-13.978-64.147-14.049-63.920Q-14.119-63.694-14.165-63.474Q-14.211-63.255-14.211-63.039Q-14.211-62.696-14.046-62.486Q-13.882-62.275-13.548-62.275Q-12.893-62.275-12.414-63.255Q-12.269-63.536-12.124-63.953Q-11.979-64.371-11.979-64.630Q-11.979-64.885-12.058-65.028Q-12.137-65.171-12.289-65.351Q-12.440-65.531-12.440-65.623Q-12.440-65.803-12.293-65.951Q-12.146-66.098-11.961-66.098Q-11.737-66.098-11.638-65.891Q-11.539-65.685-11.539-65.434Q-11.539-65.012-11.680-64.435Q-11.821-63.857-12.089-63.296Q-12.357-62.736-12.733-62.373Q-13.108-62.011-13.565-62.011Q-14.150-62.011-14.506-62.297Q-14.862-62.582-14.862-63.158",[2355],[2344,2941],{"fill":2346,"d":2942},"M-5.91-35.082c0-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-5.91-8.052c0-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.959S-5.91-2.552-5.91-8.052ZM-5.91 18.979c0-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.958S-5.91 24.48-5.91 18.98ZM-5.91 46.009c0-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.958S-5.91 51.51-5.91 46.01ZM-5.91 73.039c0-5.5-4.458-9.958-9.958-9.958s-9.959 4.458-9.959 9.958 4.459 9.958 9.959 9.958S-5.91 78.54-5.91 73.04ZM-15.868-51.953v6.713m0 20.317v6.713m0 20.317V8.82m0 20.317v6.713m0 20.317v6.714",[2339,2944,2945,2948,2951],{"fill":2382,"stroke":2382,"style":2383},[2344,2946],{"fill":2346,"d":2947},"M-6.323-58.637c7.36 2.678 7.36 17.403 2.443 19.192",[2344,2949],{"stroke":2346,"d":2950},"m-6.323-38.556 4.62.532-2.177-1.421.755-2.488",[2339,2952,2953,2960],{"fill":2382,"stroke":2346},[2339,2954,2956],{"transform":2955},"translate(24.06 16.86)",[2344,2957],{"d":2958,"fill":2382,"stroke":2382,"className":2959,"style":2399},"M-12.282-62.112L-15.442-62.112L-15.442-62.319Q-15.442-62.346-15.419-62.378L-14.067-63.776Q-13.688-64.163-13.440-64.452Q-13.192-64.741-13.018-65.098Q-12.845-65.456-12.845-65.846Q-12.845-66.194-12.977-66.487Q-13.110-66.780-13.364-66.958Q-13.618-67.135-13.973-67.135Q-14.333-67.135-14.624-66.940Q-14.915-66.745-15.059-66.417L-15.005-66.417Q-14.821-66.417-14.696-66.296Q-14.571-66.174-14.571-65.983Q-14.571-65.803-14.696-65.674Q-14.821-65.546-15.005-65.546Q-15.184-65.546-15.313-65.674Q-15.442-65.803-15.442-65.983Q-15.442-66.385-15.222-66.721Q-15.001-67.057-14.636-67.245Q-14.270-67.432-13.868-67.432Q-13.388-67.432-12.972-67.245Q-12.556-67.057-12.304-66.696Q-12.052-66.335-12.052-65.846Q-12.052-65.487-12.206-65.184Q-12.360-64.882-12.612-64.622Q-12.864-64.362-13.214-64.077Q-13.563-63.792-13.731-63.639L-14.661-62.800L-13.946-62.800Q-12.571-62.800-12.532-62.839Q-12.462-62.917-12.419-63.102Q-12.376-63.288-12.333-63.577L-12.052-63.577",[2355],[2339,2961,2962],{"transform":2955},[2344,2963],{"d":2964,"fill":2382,"stroke":2382,"className":2965,"style":2406},"M-9.787-64.809Q-10.349-64.809-10.679-65.096Q-11.009-65.383-11.136-65.833Q-11.264-66.283-11.264-66.848Q-11.264-67.252-11.198-67.617Q-11.132-67.982-10.969-68.278Q-10.806-68.574-10.515-68.749Q-10.223-68.925-9.787-68.925Q-9.350-68.925-9.060-68.749Q-8.770-68.574-8.606-68.279Q-8.442-67.985-8.378-67.627Q-8.313-67.270-8.313-66.848Q-8.313-66.283-8.441-65.833Q-8.568-65.383-8.895-65.096Q-9.222-64.809-9.787-64.809M-9.787-65.026Q-9.383-65.026-9.188-65.336Q-8.993-65.647-8.949-66.039Q-8.905-66.432-8.905-66.945Q-8.905-67.440-8.949-67.799Q-8.993-68.158-9.188-68.433Q-9.383-68.708-9.787-68.708Q-10.191-68.708-10.386-68.433Q-10.581-68.158-10.625-67.799Q-10.669-67.440-10.669-66.945Q-10.669-66.432-10.625-66.039Q-10.581-65.647-10.386-65.336Q-10.191-65.026-9.787-65.026",[2355],[2339,2967,2968,2971,2974],{"fill":2382,"stroke":2382,"style":2383},[2344,2969],{"fill":2346,"d":2970},"M-23.052-27.898C-48.904-2.046-48.904 40.003-24.89 64.017",[2344,2972],{"stroke":2346,"d":2973},"m-23.052 65.856-1.47-4.412-.368 2.573-2.574.368",[2339,2975,2976,2982],{"fill":2382,"stroke":2346},[2339,2977,2979],{"transform":2978},"translate(-43.985 84.435)",[2344,2980],{"d":2958,"fill":2382,"stroke":2382,"className":2981,"style":2399},[2355],[2339,2983,2984],{"transform":2978},[2344,2985],{"d":2986,"fill":2382,"stroke":2382,"className":2987,"style":2406},"M-8.577-64.935L-11.187-64.935L-11.187-65.120Q-11.181-65.143-11.161-65.169L-10.010-66.224Q-9.670-66.535-9.490-66.721Q-9.309-66.907-9.164-67.167Q-9.019-67.428-9.019-67.724Q-9.019-67.997-9.145-68.212Q-9.271-68.427-9.491-68.547Q-9.711-68.667-9.986-68.667Q-10.162-68.667-10.332-68.610Q-10.502-68.553-10.634-68.446Q-10.765-68.339-10.845-68.181Q-10.757-68.181-10.679-68.137Q-10.601-68.093-10.557-68.017Q-10.514-67.941-10.514-67.844Q-10.514-67.704-10.610-67.607Q-10.707-67.510-10.850-67.510Q-10.988-67.510-11.088-67.610Q-11.187-67.709-11.187-67.844Q-11.187-68.169-10.997-68.417Q-10.806-68.664-10.503-68.795Q-10.200-68.925-9.884-68.925Q-9.503-68.925-9.160-68.790Q-8.817-68.656-8.603-68.383Q-8.389-68.111-8.389-67.724Q-8.389-67.449-8.514-67.222Q-8.639-66.995-8.819-66.823Q-8.999-66.652-9.324-66.412Q-9.649-66.171-9.734-66.104L-10.490-65.500L-9.957-65.500Q-9.468-65.500-9.137-65.508Q-8.806-65.515-8.791-65.530Q-8.732-65.600-8.700-65.735Q-8.668-65.870-8.636-66.081L-8.389-66.081",[2355],[2339,2989,2990,2997,3003,3009],{"stroke":2346},[2339,2991,2993],{"transform":2992},"translate(40.655 83.113)",[2344,2994],{"d":2995,"fill":2341,"stroke":2341,"className":2996,"style":2399},"M-15.028-62.991L-15.091-62.991Q-14.950-62.639-14.626-62.428Q-14.302-62.217-13.915-62.217Q-13.321-62.217-13.071-62.651Q-12.821-63.085-12.821-63.721Q-12.821-64.315-12.991-64.762Q-13.161-65.210-13.661-65.210Q-13.958-65.210-14.163-65.130Q-14.368-65.049-14.470-64.958Q-14.571-64.866-14.686-64.733Q-14.802-64.600-14.852-64.585L-14.923-64.585Q-15.009-64.608-15.028-64.686L-15.028-67.335Q-14.997-67.432-14.923-67.432Q-14.907-67.432-14.899-67.430Q-14.891-67.428-14.884-67.424Q-14.298-67.174-13.700-67.174Q-13.118-67.174-12.501-67.432L-12.477-67.432Q-12.434-67.432-12.407-67.407Q-12.380-67.382-12.380-67.342L-12.380-67.264Q-12.380-67.233-12.403-67.210Q-12.700-66.858-13.122-66.661Q-13.544-66.464-14.005-66.464Q-14.352-66.464-14.731-66.569L-14.731-65.073Q-14.513-65.268-14.237-65.366Q-13.962-65.464-13.661-65.464Q-13.204-65.464-12.835-65.216Q-12.466-64.967-12.259-64.563Q-12.052-64.159-12.052-63.714Q-12.052-63.225-12.307-62.817Q-12.563-62.409-12.995-62.176Q-13.427-61.944-13.915-61.944Q-14.309-61.944-14.665-62.135Q-15.020-62.327-15.231-62.661Q-15.442-62.995-15.442-63.409Q-15.442-63.589-15.325-63.702Q-15.208-63.815-15.028-63.815Q-14.911-63.815-14.819-63.762Q-14.727-63.710-14.675-63.618Q-14.622-63.526-14.622-63.409Q-14.622-63.225-14.735-63.108Q-14.848-62.991-15.028-62.991",[2355],[2339,2998,2999],{"transform":2992},[2344,3000],{"d":3001,"fill":2341,"stroke":2341,"className":3002,"style":2399},"M-3.296-63.089L-8.609-63.089Q-8.687-63.096-8.736-63.145Q-8.784-63.194-8.784-63.272Q-8.784-63.342-8.737-63.393Q-8.691-63.444-8.609-63.456L-3.296-63.456Q-3.222-63.444-3.175-63.393Q-3.128-63.342-3.128-63.272Q-3.128-63.194-3.177-63.145Q-3.226-63.096-3.296-63.089M-3.296-64.776L-8.609-64.776Q-8.687-64.784-8.736-64.833Q-8.784-64.882-8.784-64.960Q-8.784-65.030-8.737-65.081Q-8.691-65.132-8.609-65.143L-3.296-65.143Q-3.222-65.132-3.175-65.081Q-3.128-65.030-3.128-64.960Q-3.128-64.882-3.177-64.833Q-3.226-64.784-3.296-64.776",[2355],[2339,3004,3005],{"transform":2992},[2344,3006],{"d":3007,"fill":2341,"stroke":2341,"className":3008,"style":2399},"M3.309-62.112L0.516-62.112L0.516-62.409Q1.578-62.409 1.578-62.671L1.578-66.839Q1.149-66.624 0.469-66.624L0.469-66.921Q1.488-66.921 2.004-67.432L2.149-67.432Q2.223-67.413 2.242-67.335L2.242-62.671Q2.242-62.409 3.309-62.409L3.309-62.112M6.082-61.944Q5.379-61.944 4.979-62.344Q4.578-62.745 4.434-63.354Q4.289-63.964 4.289-64.663Q4.289-65.186 4.360-65.649Q4.430-66.112 4.623-66.524Q4.817-66.936 5.174-67.184Q5.531-67.432 6.082-67.432Q6.633-67.432 6.990-67.184Q7.348-66.936 7.539-66.526Q7.731-66.116 7.801-65.647Q7.871-65.178 7.871-64.663Q7.871-63.964 7.729-63.356Q7.586-62.749 7.186-62.346Q6.785-61.944 6.082-61.944M6.082-62.202Q6.555-62.202 6.787-62.637Q7.020-63.073 7.074-63.612Q7.129-64.151 7.129-64.792Q7.129-65.788 6.945-66.481Q6.762-67.174 6.082-67.174Q5.715-67.174 5.494-66.936Q5.274-66.698 5.178-66.341Q5.082-65.983 5.057-65.612Q5.031-65.241 5.031-64.792Q5.031-64.151 5.086-63.612Q5.141-63.073 5.373-62.637Q5.606-62.202 6.082-62.202M11.801-62.112L9.008-62.112L9.008-62.409Q10.070-62.409 10.070-62.671L10.070-66.839Q9.641-66.624 8.961-66.624L8.961-66.921Q9.981-66.921 10.496-67.432L10.641-67.432Q10.715-67.413 10.735-67.335L10.735-62.671Q10.735-62.409 11.801-62.409",[2355],[2339,3010,3011],{"transform":2992},[2344,3012],{"d":3013,"fill":2341,"stroke":2341,"className":3014,"style":2406},"M15.506-61L12.896-61L12.896-61.185Q12.902-61.208 12.922-61.234L14.073-62.289Q14.413-62.600 14.593-62.786Q14.774-62.972 14.919-63.232Q15.064-63.493 15.064-63.789Q15.064-64.062 14.938-64.277Q14.812-64.492 14.592-64.612Q14.372-64.732 14.097-64.732Q13.921-64.732 13.751-64.675Q13.581-64.618 13.449-64.511Q13.318-64.404 13.238-64.246Q13.326-64.246 13.404-64.202Q13.482-64.158 13.526-64.082Q13.569-64.006 13.569-63.909Q13.569-63.769 13.473-63.672Q13.376-63.575 13.233-63.575Q13.095-63.575 12.995-63.675Q12.896-63.774 12.896-63.909Q12.896-64.234 13.086-64.482Q13.277-64.729 13.580-64.860Q13.883-64.990 14.199-64.990Q14.580-64.990 14.923-64.855Q15.266-64.721 15.480-64.448Q15.694-64.176 15.694-63.789Q15.694-63.514 15.569-63.287Q15.444-63.060 15.264-62.888Q15.084-62.717 14.759-62.477Q14.434-62.236 14.349-62.169L13.593-61.565L14.126-61.565Q14.615-61.565 14.946-61.573Q15.277-61.580 15.292-61.595Q15.351-61.665 15.383-61.800Q15.415-61.935 15.447-62.146L15.694-62.146",[2355],[2481,3016,3018,3097,3098,3113,3114,3155,3156,3197],{"className":3017},[2484],[390,3019,3021],{"className":3020},[393],[390,3022,3024,3043],{"className":3023,"ariaHidden":398},[397],[390,3025,3027,3030,3034,3037,3040],{"className":3026},[402],[390,3028],{"className":3029,"style":1448},[406],[390,3031,3033],{"className":3032},[411],"5",[390,3035],{"className":3036,"style":845},[612],[390,3038,850],{"className":3039},[849],[390,3041],{"className":3042,"style":845},[612],[390,3044,3046,3050,3054],{"className":3045},[402],[390,3047],{"className":3048,"style":3049},[406],"height:0.7944em;vertical-align:-0.15em;",[390,3051,3053],{"className":3052},[411],"10",[390,3055,3057,3060],{"className":3056},[411],[390,3058,1402],{"className":3059},[411],[390,3061,3063],{"className":3062},[1046],[390,3064,3066,3088],{"className":3065},[1050,2063],[390,3067,3069,3085],{"className":3068},[1054],[390,3070,3073],{"className":3071,"style":3072},[1058],"height:0.3011em;",[390,3074,3076,3079],{"style":3075},"top:-2.55em;margin-left:0em;margin-right:0.05em;",[390,3077],{"className":3078,"style":1066},[1065],[390,3080,3082],{"className":3081},[1070,1071,1072,1073],[390,3083,1042],{"className":3084},[411,1073],[390,3086,2087],{"className":3087},[2086],[390,3089,3091],{"className":3090},[1054],[390,3092,3095],{"className":3093,"style":3094},[1058],"height:0.15em;",[390,3096],{}," splits the ",[390,3099,3101],{"className":3100},[393],[390,3102,3104],{"className":3103,"ariaHidden":398},[397],[390,3105,3107,3110],{"className":3106},[402],[390,3108],{"className":3109,"style":1448},[406],[390,3111,3033],{"className":3112},[411],"-edge climb into a ",[390,3115,3117],{"className":3116},[393],[390,3118,3120],{"className":3119,"ariaHidden":398},[397],[390,3121,3123,3126],{"className":3122},[402],[390,3124],{"className":3125,"style":2713},[406],[390,3127,3129,3132],{"className":3128},[411],[390,3130,1042],{"className":3131},[411],[390,3133,3135],{"className":3134},[1046],[390,3136,3138],{"className":3137},[1050],[390,3139,3141],{"className":3140},[1054],[390,3142,3144],{"className":3143,"style":2713},[1058],[390,3145,3146,3149],{"style":1061},[390,3147],{"className":3148,"style":1066},[1065],[390,3150,3152],{"className":3151},[1070,1071,1072,1073],[390,3153,1257],{"className":3154},[411,1073]," jump then a ",[390,3157,3159],{"className":3158},[393],[390,3160,3162],{"className":3161,"ariaHidden":398},[397],[390,3163,3165,3168],{"className":3164},[402],[390,3166],{"className":3167,"style":2713},[406],[390,3169,3171,3174],{"className":3170},[411],[390,3172,1042],{"className":3173},[411],[390,3175,3177],{"className":3176},[1046],[390,3178,3180],{"className":3179},[1050],[390,3181,3183],{"className":3182},[1054],[390,3184,3186],{"className":3185,"style":2713},[1058],[390,3187,3188,3191],{"style":1061},[390,3189],{"className":3190,"style":1066},[1065],[390,3192,3194],{"className":3193},[1070,1071,1072,1073],[390,3195,1042],{"className":3196},[411,1073]," jump (one per set bit)",[2595,3199,3201,3202],{"id":3200},"lca-in-ologn","LCA in ",[390,3203,3205],{"className":3204},[393],[390,3206,3208],{"className":3207,"ariaHidden":398},[397],[390,3209,3211,3214,3217,3220,3226,3229,3232],{"className":3210},[402],[390,3212],{"className":3213,"style":586},[406],[390,3215,798],{"className":3216,"style":463},[411,412],[390,3218,600],{"className":3219},[599],[390,3221,3223],{"className":3222},[590],[390,3224,873],{"className":3225,"style":872},[411,594],[390,3227],{"className":3228,"style":613},[612],[390,3230,880],{"className":3231},[411,412],[390,3233,621],{"className":3234},[620],[381,3236,3237,3238,3241,3242,3313,3314,3338,3339,414,3354,3369,3370,3373,3374,3377,3378,3393,3394,573,3435,3438,3439,414,3454,3469,3470,3473],{},"The LCA query reuses the same jumps as two phases. ",[434,3239,3240],{},"Phase 1"," lifts the deeper\nnode up by exactly ",[390,3243,3245],{"className":3244},[393],[390,3246,3248,3286],{"className":3247,"ariaHidden":398},[397],[390,3249,3251,3254,3258,3261,3265,3268,3271,3274,3277,3280,3283],{"className":3250},[402],[390,3252],{"className":3253,"style":586},[406],[390,3255,3257],{"className":3256},[411,412],"d",[390,3259,1288],{"className":3260},[411,412],[390,3262,3264],{"className":3263},[411,412],"pt",[390,3266,805],{"className":3267},[411,412],[390,3269,1106],{"className":3270},[599],[390,3272,413],{"className":3273},[411,412],[390,3275,1113],{"className":3276},[620],[390,3278],{"className":3279,"style":1546},[612],[390,3281,1398],{"className":3282},[1397],[390,3284],{"className":3285,"style":1546},[612],[390,3287,3289,3292,3295,3298,3301,3304,3307,3310],{"className":3288},[402],[390,3290],{"className":3291,"style":586},[406],[390,3293,3257],{"className":3294},[411,412],[390,3296,1288],{"className":3297},[411,412],[390,3299,3264],{"className":3300},[411,412],[390,3302,805],{"className":3303},[411,412],[390,3305,1106],{"className":3306},[599],[390,3308,431],{"className":3309,"style":430},[411,412],[390,3311,1113],{"className":3312},[620],", a single ",[390,3315,3317],{"className":3316},[393],[390,3318,3320],{"className":3319,"ariaHidden":398},[397],[390,3321,3323,3326],{"className":3322},[402],[390,3324],{"className":3325,"style":822},[406],[390,3327,3330],{"className":3328},[1951,3329],"textsc",[390,3331,3334],{"className":3332},[411,3333],"text",[390,3335,3337],{"className":3336},[411],"Kth-Ancestor"," call,\nso ",[390,3340,3342],{"className":3341},[393],[390,3343,3345],{"className":3344,"ariaHidden":398},[397],[390,3346,3348,3351],{"className":3347},[402],[390,3349],{"className":3350,"style":407},[406],[390,3352,413],{"className":3353},[411,412],[390,3355,3357],{"className":3356},[393],[390,3358,3360],{"className":3359,"ariaHidden":398},[397],[390,3361,3363,3366],{"className":3362},[402],[390,3364],{"className":3365,"style":407},[406],[390,3367,431],{"className":3368,"style":430},[411,412]," sit at equal depth. If they now coincide, one was an ancestor of\nthe other and we are done. ",[434,3371,3372],{},"Phase 2"," lifts ",[385,3375,3376],{},"both"," nodes simultaneously: scanning\n",[390,3379,3381],{"className":3380},[393],[390,3382,3384],{"className":3383,"ariaHidden":398},[397],[390,3385,3387,3390],{"className":3386},[402],[390,3388],{"className":3389,"style":822},[406],[390,3391,1021],{"className":3392,"style":1020},[411,412]," from high to low, we jump both up by ",[390,3395,3397],{"className":3396},[393],[390,3398,3400],{"className":3399,"ariaHidden":398},[397],[390,3401,3403,3406],{"className":3402},[402],[390,3404],{"className":3405,"style":1035},[406],[390,3407,3409,3412],{"className":3408},[411],[390,3410,1042],{"className":3411},[411],[390,3413,3415],{"className":3414},[1046],[390,3416,3418],{"className":3417},[1050],[390,3419,3421],{"className":3420},[1054],[390,3422,3424],{"className":3423,"style":1035},[1058],[390,3425,3426,3429],{"style":1061},[390,3427],{"className":3428,"style":1066},[1065],[390,3430,3432],{"className":3431},[1070,1071,1072,1073],[390,3433,1021],{"className":3434,"style":1020},[411,412,1073],[434,3436,3437],{},"only when that keeps them\ndistinct",". When the loop ends, ",[390,3440,3442],{"className":3441},[393],[390,3443,3445],{"className":3444,"ariaHidden":398},[397],[390,3446,3448,3451],{"className":3447},[402],[390,3449],{"className":3450,"style":407},[406],[390,3452,413],{"className":3453},[411,412],[390,3455,3457],{"className":3456},[393],[390,3458,3460],{"className":3459,"ariaHidden":398},[397],[390,3461,3463,3466],{"className":3462},[402],[390,3464],{"className":3465,"style":407},[406],[390,3467,431],{"className":3468,"style":430},[411,412]," are the two distinct children-side\nnodes just ",[385,3471,3472],{},"below"," the LCA, so the answer is their common parent.",[728,3475,3477],{"className":730,"code":3476,"language":732,"meta":376,"style":376},"caption: $\\textsc{LCA}(u, v)$ — equalize depth, then jump both up greedily\nif $depth[u] \u003C depth[v]$ then swap $u, v$\n$u \\gets \\textsc{Kth-Ancestor}(u,\\ depth[u] - depth[v])$  \u002F\u002F phase 1\nif $u = v$ then return $u$\nfor $k \\gets K$ downto $0$ do                              \u002F\u002F phase 2\n  if $up[u][k] \\ne up[v][k]$ then\n    $u \\gets up[u][k]$\n    $v \\gets up[v][k]$\nreturn $up[u][0]$  \u002F\u002F their common parent\n",[734,3478,3479,3484,3489,3494,3499,3504,3509,3514,3519],{"__ignoreMap":376},[390,3480,3481],{"class":738,"line":6},[390,3482,3483],{},"caption: $\\textsc{LCA}(u, v)$ — equalize depth, then jump both up greedily\n",[390,3485,3486],{"class":738,"line":18},[390,3487,3488],{},"if $depth[u] \u003C depth[v]$ then swap $u, v$\n",[390,3490,3491],{"class":738,"line":24},[390,3492,3493],{},"$u \\gets \\textsc{Kth-Ancestor}(u,\\ depth[u] - depth[v])$  \u002F\u002F phase 1\n",[390,3495,3496],{"class":738,"line":73},[390,3497,3498],{},"if $u = v$ then return $u$\n",[390,3500,3501],{"class":738,"line":102},[390,3502,3503],{},"for $k \\gets K$ downto $0$ do                              \u002F\u002F phase 2\n",[390,3505,3506],{"class":738,"line":108},[390,3507,3508],{},"  if $up[u][k] \\ne up[v][k]$ then\n",[390,3510,3511],{"class":738,"line":116},[390,3512,3513],{},"    $u \\gets up[u][k]$\n",[390,3515,3516],{"class":738,"line":196},[390,3517,3518],{},"    $v \\gets up[v][k]$\n",[390,3520,3521],{"class":738,"line":202},[390,3522,3523],{},"return $up[u][0]$  \u002F\u002F their common parent\n",[439,3525,3527],{"type":3526},"remark",[381,3528,3529,1084,3532,3547,3548,3563,3564,3579,3580,414,3595,3610,3611,3644,3645,3660,3661,3664,3665,3698,3699,3740,3741,414,3777,3813],{},[434,3530,3531],{},"Remark (Why high-to-low greedy is correct).",[390,3533,3535],{"className":3534},[393],[390,3536,3538],{"className":3537,"ariaHidden":398},[397],[390,3539,3541,3544],{"className":3540},[402],[390,3542],{"className":3543,"style":822},[406],[390,3545,3257],{"className":3546},[411,412]," be the number of edges from the\nequalized ",[390,3549,3551],{"className":3550},[393],[390,3552,3554],{"className":3553,"ariaHidden":398},[397],[390,3555,3557,3560],{"className":3556},[402],[390,3558],{"className":3559,"style":407},[406],[390,3561,413],{"className":3562},[411,412]," up to the LCA (the same for ",[390,3565,3567],{"className":3566},[393],[390,3568,3570],{"className":3569,"ariaHidden":398},[397],[390,3571,3573,3576],{"className":3572},[402],[390,3574],{"className":3575,"style":407},[406],[390,3577,431],{"className":3578,"style":430},[411,412],"). We must climb ",[390,3581,3583],{"className":3582},[393],[390,3584,3586],{"className":3585,"ariaHidden":398},[397],[390,3587,3589,3592],{"className":3588},[402],[390,3590],{"className":3591,"style":407},[406],[390,3593,413],{"className":3594},[411,412],[390,3596,3598],{"className":3597},[393],[390,3599,3601],{"className":3600,"ariaHidden":398},[397],[390,3602,3604,3607],{"className":3603},[402],[390,3605],{"className":3606,"style":407},[406],[390,3608,431],{"className":3609,"style":430},[411,412]," up by\nexactly ",[390,3612,3614],{"className":3613},[393],[390,3615,3617,3635],{"className":3616,"ariaHidden":398},[397],[390,3618,3620,3623,3626,3629,3632],{"className":3619},[402],[390,3621],{"className":3622,"style":1989},[406],[390,3624,3257],{"className":3625},[411,412],[390,3627],{"className":3628,"style":1546},[612],[390,3630,1398],{"className":3631},[1397],[390,3633],{"className":3634,"style":1546},[612],[390,3636,3638,3641],{"className":3637},[402],[390,3639],{"className":3640,"style":1448},[406],[390,3642,1402],{"className":3643},[411],", stopping one short so they land on the LCA's two distinct\ndescendants, and then take one parent step. Scanning ",[390,3646,3648],{"className":3647},[393],[390,3649,3651],{"className":3650,"ariaHidden":398},[397],[390,3652,3654,3657],{"className":3653},[402],[390,3655],{"className":3656,"style":822},[406],[390,3658,1021],{"className":3659,"style":1020},[411,412]," from high to low and\njumping whenever the targets ",[385,3662,3663],{},"differ"," is precisely the greedy construction of\n",[390,3666,3668],{"className":3667},[393],[390,3669,3671,3689],{"className":3670,"ariaHidden":398},[397],[390,3672,3674,3677,3680,3683,3686],{"className":3673},[402],[390,3675],{"className":3676,"style":1989},[406],[390,3678,3257],{"className":3679},[411,412],[390,3681],{"className":3682,"style":1546},[612],[390,3684,1398],{"className":3685},[1397],[390,3687],{"className":3688,"style":1546},[612],[390,3690,3692,3695],{"className":3691},[402],[390,3693],{"className":3694,"style":1448},[406],[390,3696,1402],{"className":3697},[411]," in binary: a jump of ",[390,3700,3702],{"className":3701},[393],[390,3703,3705],{"className":3704,"ariaHidden":398},[397],[390,3706,3708,3711],{"className":3707},[402],[390,3709],{"className":3710,"style":1035},[406],[390,3712,3714,3717],{"className":3713},[411],[390,3715,1042],{"className":3716},[411],[390,3718,3720],{"className":3719},[1046],[390,3721,3723],{"className":3722},[1050],[390,3724,3726],{"className":3725},[1054],[390,3727,3729],{"className":3728,"style":1035},[1058],[390,3730,3731,3734],{"style":1061},[390,3732],{"className":3733,"style":1066},[1065],[390,3735,3737],{"className":3736},[1070,1071,1072,1073],[390,3738,1021],{"className":3739,"style":1020},[411,412,1073]," is taken iff it does not overshoot the LCA\n(overshooting would make ",[390,3742,3744],{"className":3743},[393],[390,3745,3747],{"className":3746,"ariaHidden":398},[397],[390,3748,3750,3753,3756,3759,3762,3765,3768,3771,3774],{"className":3749},[402],[390,3751],{"className":3752,"style":586},[406],[390,3754,413],{"className":3755},[411,412],[390,3757,381],{"className":3758},[411,412],[390,3760,1106],{"className":3761},[599],[390,3763,413],{"className":3764},[411,412],[390,3766,1113],{"className":3767},[620],[390,3769,1106],{"className":3770},[599],[390,3772,1021],{"className":3773,"style":1020},[411,412],[390,3775,1113],{"className":3776},[620],[390,3778,3780],{"className":3779},[393],[390,3781,3783],{"className":3782,"ariaHidden":398},[397],[390,3784,3786,3789,3792,3795,3798,3801,3804,3807,3810],{"className":3785},[402],[390,3787],{"className":3788,"style":586},[406],[390,3790,413],{"className":3791},[411,412],[390,3793,381],{"className":3794},[411,412],[390,3796,1106],{"className":3797},[599],[390,3799,431],{"className":3800,"style":430},[411,412],[390,3802,1113],{"className":3803},[620],[390,3805,1106],{"className":3806},[599],[390,3808,1021],{"className":3809,"style":1020},[411,412],[390,3811,1113],{"className":3812},[620]," equal). It is the same\nhigh-to-low bit selection used throughout binary lifting.",[381,3815,3816,3817,3850,3851,3884,3885,3918,3919,3958],{},"The depth-equalizing jump is ",[390,3818,3820],{"className":3819},[393],[390,3821,3823],{"className":3822,"ariaHidden":398},[397],[390,3824,3826,3829,3832,3835,3841,3844,3847],{"className":3825},[402],[390,3827],{"className":3828,"style":586},[406],[390,3830,798],{"className":3831,"style":463},[411,412],[390,3833,600],{"className":3834},[599],[390,3836,3838],{"className":3837},[590],[390,3839,873],{"className":3840,"style":872},[411,594],[390,3842],{"className":3843,"style":613},[612],[390,3845,880],{"className":3846},[411,412],[390,3848,621],{"className":3849},[620]," and the second loop runs ",[390,3852,3854],{"className":3853},[393],[390,3855,3857,3875],{"className":3856,"ariaHidden":398},[397],[390,3858,3860,3863,3866,3869,3872],{"className":3859},[402],[390,3861],{"className":3862,"style":2860},[406],[390,3864,2028],{"className":3865,"style":2027},[411,412],[390,3867],{"className":3868,"style":1546},[612],[390,3870,1842],{"className":3871},[1397],[390,3873],{"className":3874,"style":1546},[612],[390,3876,3878,3881],{"className":3877},[402],[390,3879],{"className":3880,"style":1448},[406],[390,3882,1402],{"className":3883},[411]," times, so\neach LCA query is ",[390,3886,3888],{"className":3887},[393],[390,3889,3891],{"className":3890,"ariaHidden":398},[397],[390,3892,3894,3897,3900,3903,3909,3912,3915],{"className":3893},[402],[390,3895],{"className":3896,"style":586},[406],[390,3898,798],{"className":3899,"style":463},[411,412],[390,3901,600],{"className":3902},[599],[390,3904,3906],{"className":3905},[590],[390,3907,873],{"className":3908,"style":872},[411,594],[390,3910],{"className":3911,"style":613},[612],[390,3913,880],{"className":3914},[411,412],[390,3916,621],{"className":3917},[620]," after the one-time ",[390,3920,3922],{"className":3921},[393],[390,3923,3925],{"className":3924,"ariaHidden":398},[397],[390,3926,3928,3931,3934,3937,3940,3943,3949,3952,3955],{"className":3927},[402],[390,3929],{"className":3930,"style":586},[406],[390,3932,798],{"className":3933,"style":463},[411,412],[390,3935,600],{"className":3936},[599],[390,3938,880],{"className":3939},[411,412],[390,3941],{"className":3942,"style":613},[612],[390,3944,3946],{"className":3945},[590],[390,3947,873],{"className":3948,"style":872},[411,594],[390,3950],{"className":3951,"style":613},[612],[390,3953,880],{"className":3954},[411,412],[390,3956,621],{"className":3957},[620]," build.",[2326,3960,3962,4070],{"className":3961},[2329,2330],[2332,3963,3967],{"xmlns":2334,"width":3964,"height":3965,"viewBox":3966},"129.336","160.281","-75 -75 97.002 120.211",[2339,3968,3969,3972,3979,3982,3989,3992,3999,4002,4009,4012,4019,4022,4029,4032,4037,4046,4054,4062],{"stroke":2341,"style":2342},[2344,3970],{"fill":2346,"d":3971},"M18.532-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",[2339,3973,3975],{"transform":3974},"translate(-2.215 1.937)",[2344,3976],{"d":3977,"fill":2341,"stroke":2341,"className":3978,"style":2356},"M9.312-62.283Q9.312-62.336 9.321-62.371L9.989-65.039Q10.042-65.237 10.042-65.434Q10.042-65.830 9.778-65.830Q9.492-65.830 9.358-65.507Q9.224-65.184 9.106-64.678Q9.088-64.595 9.013-64.595L8.908-64.595Q8.860-64.595 8.838-64.634Q8.816-64.674 8.816-64.714Q8.978-65.333 9.178-65.711Q9.378-66.089 9.800-66.089Q10.108-66.089 10.354-65.915Q10.600-65.742 10.670-65.452Q11.171-66.089 11.839-66.089Q12.138-66.089 12.358-65.913Q12.577-65.737 12.577-65.443Q12.577-65.210 12.430-65.039Q12.283-64.867 12.059-64.867Q11.918-64.867 11.813-64.960Q11.707-65.052 11.707-65.197Q11.707-65.395 11.841-65.542Q11.975-65.689 12.173-65.711Q12.037-65.830 11.822-65.830Q11.145-65.830 10.626-64.885L9.998-62.336Q9.967-62.200 9.851-62.105Q9.734-62.011 9.598-62.011Q9.479-62.011 9.396-62.086Q9.312-62.160 9.312-62.283",[2355],[2344,3980],{"fill":2346,"d":3981},"M-2.807-30.814c0-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",[2339,3983,3985],{"transform":3984},"translate(-23.79 33.236)",[2344,3986],{"d":3987,"fill":2341,"stroke":2341,"className":3988,"style":2356},"M10.196-62.011Q9.800-62.011 9.514-62.215Q9.229-62.420 9.082-62.754Q8.934-63.088 8.934-63.479Q8.934-63.914 9.108-64.375Q9.282-64.837 9.594-65.228Q9.906-65.619 10.316-65.854Q10.727-66.089 11.167-66.089Q11.435-66.089 11.652-65.951Q11.870-65.812 12.002-65.566Q12.041-65.716 12.149-65.812Q12.257-65.909 12.397-65.909Q12.520-65.909 12.604-65.836Q12.687-65.764 12.687-65.641Q12.687-65.588 12.678-65.557L12.059-63.066Q12.002-62.868 12.002-62.670Q12.002-62.275 12.265-62.275Q12.551-62.275 12.685-62.598Q12.819-62.921 12.938-63.426Q12.947-63.457 12.971-63.481Q12.995-63.505 13.030-63.505L13.136-63.505Q13.184-63.505 13.206-63.472Q13.228-63.439 13.228-63.391Q13.114-62.960 13.023-62.707Q12.933-62.455 12.740-62.233Q12.547-62.011 12.248-62.011Q11.940-62.011 11.692-62.182Q11.444-62.354 11.373-62.644Q11.118-62.358 10.822-62.185Q10.525-62.011 10.196-62.011M10.213-62.275Q10.543-62.275 10.853-62.516Q11.162-62.758 11.373-63.074Q11.382-63.083 11.382-63.101L11.879-65.065Q11.822-65.382 11.630-65.606Q11.439-65.830 11.149-65.830Q10.780-65.830 10.481-65.511Q10.182-65.193 10.015-64.784Q9.879-64.437 9.754-63.927Q9.629-63.417 9.629-63.092Q9.629-62.767 9.767-62.521Q9.906-62.275 10.213-62.275",[2355],[2344,3990],{"fill":2346,"d":3991},"m2.852-53.719-9.895 14.513M-24.147.484c0-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",[2339,3993,3995],{"transform":3994},"translate(-44.681 64.534)",[2344,3996],{"d":3997,"fill":2341,"stroke":2341,"className":3998,"style":2356},"M9.664-63.219Q9.664-62.824 9.877-62.549Q10.090-62.275 10.472-62.275Q11.017-62.275 11.523-62.510Q12.028-62.745 12.345-63.167Q12.366-63.202 12.428-63.202Q12.485-63.202 12.531-63.151Q12.577-63.101 12.577-63.048Q12.577-63.013 12.551-62.987Q12.204-62.512 11.641-62.261Q11.079-62.011 10.455-62.011Q10.024-62.011 9.675-62.213Q9.325-62.415 9.134-62.771Q8.943-63.127 8.943-63.553Q8.943-64.015 9.145-64.472Q9.347-64.929 9.703-65.298Q10.059-65.667 10.503-65.878Q10.947-66.089 11.417-66.089Q11.685-66.089 11.934-66.008Q12.182-65.926 12.349-65.748Q12.516-65.570 12.516-65.307Q12.516-65.070 12.366-64.892Q12.217-64.714 11.984-64.714Q11.844-64.714 11.738-64.808Q11.633-64.903 11.633-65.048Q11.633-65.250 11.780-65.404Q11.927-65.557 12.129-65.557Q12.024-65.698 11.819-65.764Q11.615-65.830 11.408-65.830Q10.872-65.830 10.475-65.401Q10.077-64.973 9.870-64.353Q9.664-63.734 9.664-63.219",[2355],[2344,4000],{"fill":2346,"d":4001},"m-18.488-22.42-9.895 14.512M-45.486 31.783c0-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.459 9.959-9.958Zm-9.959 0",[2339,4003,4005],{"transform":4004},"translate(-66.68 95.832)",[2344,4006],{"d":4007,"fill":2341,"stroke":2341,"className":4008,"style":2356},"M9.572-63.110Q9.572-63.395 9.648-63.714Q9.725-64.032 9.840-64.333Q9.954-64.634 10.112-65.039Q10.231-65.324 10.231-65.557Q10.231-65.676 10.185-65.753Q10.138-65.830 10.033-65.830Q9.681-65.830 9.446-65.469Q9.211-65.109 9.106-64.678Q9.088-64.595 9.013-64.595L8.908-64.595Q8.860-64.595 8.838-64.634Q8.816-64.674 8.816-64.714Q8.904-65.056 9.064-65.362Q9.224-65.667 9.475-65.878Q9.725-66.089 10.051-66.089Q10.389-66.089 10.620-65.880Q10.850-65.672 10.850-65.333Q10.850-65.153 10.789-64.999Q10.758-64.911 10.606-64.516Q10.455-64.120 10.385-63.890Q10.314-63.659 10.268-63.435Q10.222-63.211 10.222-62.987Q10.222-62.688 10.352-62.481Q10.481-62.275 10.762-62.275Q11.356-62.275 11.786-62.987Q11.786-63.013 11.804-63.101L12.446-65.676Q12.481-65.817 12.595-65.904Q12.709-65.992 12.850-65.992Q12.964-65.992 13.045-65.915Q13.127-65.839 13.127-65.720Q13.127-65.667 13.118-65.641L12.481-63.066Q12.428-62.863 12.428-62.670Q12.428-62.275 12.687-62.275Q12.973-62.275 13.111-62.609Q13.250-62.943 13.364-63.426Q13.373-63.457 13.397-63.481Q13.421-63.505 13.452-63.505L13.562-63.505Q13.606-63.505 13.628-63.472Q13.650-63.439 13.650-63.391Q13.535-62.960 13.445-62.707Q13.355-62.455 13.162-62.233Q12.969-62.011 12.670-62.011Q12.384-62.011 12.149-62.160Q11.914-62.310 11.813-62.578Q11.602-62.319 11.334-62.165Q11.066-62.011 10.754-62.011Q10.389-62.011 10.125-62.138Q9.862-62.266 9.717-62.512Q9.572-62.758 9.572-63.110",[2355],[2344,4010],{"fill":2346,"d":4011},"m-39.828 8.877-9.895 14.513M18.532.484c0-5.5-4.458-9.958-9.958-9.958S-1.385-5.015-1.385.484s4.459 9.959 9.959 9.959 9.958-4.459 9.958-9.959Zm-9.958 0",[2339,4013,4015],{"transform":4014},"translate(-1.982 65.721)",[2344,4016],{"d":4017,"fill":2341,"stroke":2341,"className":4018,"style":2356},"M10.196-62.011Q9.620-62.011 9.299-62.442Q8.978-62.872 8.978-63.452Q8.978-63.857 9.062-64.085L9.941-67.583Q9.976-67.733 9.976-67.807Q9.976-67.944 9.409-67.944Q9.312-67.944 9.312-68.062Q9.312-68.119 9.343-68.190Q9.374-68.260 9.440-68.260L10.661-68.357Q10.714-68.357 10.747-68.328Q10.780-68.299 10.780-68.251L10.780-68.216L10.121-65.606Q10.644-66.089 11.167-66.089Q11.553-66.089 11.844-65.885Q12.134-65.680 12.281-65.346Q12.428-65.012 12.428-64.621Q12.428-64.037 12.125-63.428Q11.822-62.820 11.301-62.415Q10.780-62.011 10.196-62.011M10.213-62.275Q10.582-62.275 10.886-62.598Q11.189-62.921 11.347-63.316Q11.492-63.672 11.613-64.180Q11.734-64.687 11.734-65.008Q11.734-65.333 11.589-65.581Q11.444-65.830 11.149-65.830Q10.547-65.830 9.976-65.030L9.734-64.037Q9.589-63.413 9.589-63.149Q9.589-62.806 9.741-62.540Q9.892-62.275 10.213-62.275",[2355],[2344,4020],{"fill":2346,"d":4021},"M-7.043-22.42 2.85-7.909M-2.807 31.783c0-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.459 9.959-9.958Zm-9.959 0",[2339,4023,4025],{"transform":4024},"translate(-23.747 95.832)",[2344,4026],{"d":4027,"fill":2341,"stroke":2341,"className":4028,"style":2356},"M9.580-63.158Q9.580-63.356 9.633-63.613Q9.686-63.870 9.747-64.063Q9.809-64.257 9.919-64.540Q10.029-64.823 10.112-65.039Q10.231-65.324 10.231-65.557Q10.231-65.676 10.185-65.753Q10.138-65.830 10.033-65.830Q9.681-65.830 9.446-65.469Q9.211-65.109 9.106-64.678Q9.088-64.595 9.013-64.595L8.908-64.595Q8.860-64.595 8.838-64.634Q8.816-64.674 8.816-64.714Q8.904-65.056 9.064-65.362Q9.224-65.667 9.475-65.878Q9.725-66.089 10.051-66.089Q10.389-66.089 10.620-65.883Q10.850-65.676 10.850-65.333Q10.850-65.153 10.789-64.999Q10.697-64.753 10.580-64.450Q10.464-64.147 10.393-63.920Q10.323-63.694 10.277-63.474Q10.231-63.255 10.231-63.039Q10.231-62.696 10.396-62.486Q10.560-62.275 10.894-62.275Q11.549-62.275 12.028-63.255Q12.173-63.536 12.318-63.953Q12.463-64.371 12.463-64.630Q12.463-64.885 12.384-65.028Q12.305-65.171 12.153-65.351Q12.002-65.531 12.002-65.623Q12.002-65.803 12.149-65.951Q12.296-66.098 12.481-66.098Q12.705-66.098 12.804-65.891Q12.903-65.685 12.903-65.434Q12.903-65.012 12.762-64.435Q12.621-63.857 12.353-63.296Q12.085-62.736 11.709-62.373Q11.334-62.011 10.877-62.011Q10.292-62.011 9.936-62.297Q9.580-62.582 9.580-63.158",[2355],[2344,4030],{"fill":2346,"d":4031},"M2.852 8.877-7.043 23.39",[2339,4033,4035],{"stroke":2382,"style":4034},"stroke-width:1.2",[2344,4036],{"fill":2346,"d":3981},[2339,4038,4040,4043],{"fill":2382,"stroke":2382,"style":4039},"stroke-dasharray:3.0,3.0;stroke-width:.8",[2344,4041],{"fill":2346,"d":4042},"M-52.938 21.939c1.81-7.112 4.626-11.241 8.474-14.008",[2344,4044],{"stroke":2346,"d":4045},"m-42.353 6.414-4.592.74 2.481.777-.052 2.6",[2339,4047,4048,4051],{"fill":2382,"stroke":2382,"style":4039},[2344,4049],{"fill":2346,"d":4050},"M-32.466-9.54c1.227-7.504 4.43-12.202 8.732-14.758",[2344,4052],{"stroke":2346,"d":4053},"m-21.499-25.626-4.639.337 2.404.991-.279 2.585",[2339,4055,4056,4059],{"fill":2382,"stroke":2382,"style":4039},[2344,4057],{"fill":2346,"d":4058},"M-4.033 26.594c6.538-3.883 9.74-8.58 10.548-13.519",[2344,4060],{"stroke":2346,"d":4061},"M6.935 10.51 4.21 14.278l2.304-1.204 1.801 1.875",[2339,4063,4064,4067],{"fill":2382,"stroke":2382,"style":4039},[2344,4065],{"fill":2346,"d":4066},"M6.934-9.54c-1.227-7.504-4.43-12.202-8.732-14.758",[2344,4068],{"stroke":2346,"d":4069},"m-4.033-25.626 2.514 3.913-.279-2.585 2.404-.991",[2481,4071,4073],{"className":4072},[2484],"Lift the deeper node to equal depth, then jump both up by decreasing powers of two; the LCA is highlighted",[381,4075,4076,4077,414,4092,4107,4108,414,4124,4140,4141,4195,4196,437],{},"Here ",[390,4078,4080],{"className":4079},[393],[390,4081,4083],{"className":4082,"ariaHidden":398},[397],[390,4084,4086,4089],{"className":4085},[402],[390,4087],{"className":4088,"style":407},[406],[390,4090,413],{"className":4091},[411,412],[390,4093,4095],{"className":4094},[393],[390,4096,4098],{"className":4097,"ariaHidden":398},[397],[390,4099,4101,4104],{"className":4100},[402],[390,4102],{"className":4103,"style":407},[406],[390,4105,431],{"className":4106,"style":430},[411,412]," already share depth; both lift to ",[390,4109,4111],{"className":4110},[393],[390,4112,4114],{"className":4113,"ariaHidden":398},[397],[390,4115,4117,4120],{"className":4116},[402],[390,4118],{"className":4119,"style":407},[406],[390,4121,4123],{"className":4122},[411,412],"c",[390,4125,4127],{"className":4126},[393],[390,4128,4130],{"className":4129,"ariaHidden":398},[397],[390,4131,4133,4136],{"className":4132},[402],[390,4134],{"className":4135,"style":822},[406],[390,4137,4139],{"className":4138},[411,412],"b"," (kept distinct),\nthen one parent step lands on ",[390,4142,4144],{"className":4143},[393],[390,4145,4147,4165],{"className":4146,"ariaHidden":398},[397],[390,4148,4150,4153,4156,4159,4162],{"className":4149},[402],[390,4151],{"className":4152,"style":407},[406],[390,4154,500],{"className":4155},[411,412],[390,4157],{"className":4158,"style":845},[612],[390,4160,850],{"className":4161},[849],[390,4163],{"className":4164,"style":845},[612],[390,4166,4168,4171,4177,4180,4183,4186,4189,4192],{"className":4167},[402],[390,4169],{"className":4170,"style":586},[406],[390,4172,4174],{"className":4173},[590],[390,4175,595],{"className":4176},[411,594],[390,4178,600],{"className":4179},[599],[390,4181,413],{"className":4182},[411,412],[390,4184,608],{"className":4185},[607],[390,4187],{"className":4188,"style":613},[612],[390,4190,431],{"className":4191,"style":430},[411,412],[390,4193,621],{"className":4194},[620],", drawn in ",[734,4197,4198],{},"acc",[694,4200,4202],{"id":4201},"a-worked-table","A worked table",[381,4204,4205,4206,4208,4209,4261,4262,4303,4304,4319],{},"The whole method lives in the ",[734,4207,2809],{}," grid. For the small tree below, rows are nodes\nand columns are ",[390,4210,4212],{"className":4211},[393],[390,4213,4215,4233],{"className":4214,"ariaHidden":398},[397],[390,4216,4218,4221,4224,4227,4230],{"className":4217},[402],[390,4219],{"className":4220,"style":822},[406],[390,4222,1021],{"className":4223,"style":1020},[411,412],[390,4225],{"className":4226,"style":845},[612],[390,4228,850],{"className":4229},[849],[390,4231],{"className":4232,"style":845},[612],[390,4234,4236,4240,4243,4246,4249,4252,4255,4258],{"className":4235},[402],[390,4237],{"className":4238,"style":4239},[406],"height:0.8389em;vertical-align:-0.1944em;",[390,4241,1257],{"className":4242},[411],[390,4244,608],{"className":4245},[607],[390,4247],{"className":4248,"style":613},[612],[390,4250,1402],{"className":4251},[411],[390,4253,608],{"className":4254},[607],[390,4256],{"className":4257,"style":613},[612],[390,4259,1042],{"className":4260},[411],", with each entry the ",[390,4263,4265],{"className":4264},[393],[390,4266,4268],{"className":4267,"ariaHidden":398},[397],[390,4269,4271,4274],{"className":4270},[402],[390,4272],{"className":4273,"style":1035},[406],[390,4275,4277,4280],{"className":4276},[411],[390,4278,1042],{"className":4279},[411],[390,4281,4283],{"className":4282},[1046],[390,4284,4286],{"className":4285},[1050],[390,4287,4289],{"className":4288},[1054],[390,4290,4292],{"className":4291,"style":1035},[1058],[390,4293,4294,4297],{"style":1061},[390,4295],{"className":4296,"style":1066},[1065],[390,4298,4300],{"className":4299},[1070,1071,1072,1073],[390,4301,1021],{"className":4302,"style":1020},[411,412,1073],"-th ancestor. Column ",[390,4305,4307],{"className":4306},[393],[390,4308,4310],{"className":4309,"ariaHidden":398},[397],[390,4311,4313,4316],{"className":4312},[402],[390,4314],{"className":4315,"style":1448},[406],[390,4317,1257],{"className":4318},[411]," is\nthe parent; every later column is the previous column composed with itself.",[2326,4321,4323,4522],{"className":4322},[2329,2330],[2332,4324,4328],{"xmlns":2334,"width":4325,"height":4326,"viewBox":4327},"184.345","114.490","-75 -75 138.259 85.868",[2339,4329,4330,4347,4368,4387,4406,4409,4416,4428,4431,4438,4450,4453,4459,4462,4468,4471,4477,4480,4486,4489,4495,4498,4504,4507,4513,4516],{"stroke":2341,"style":2342},[2339,4331,4334,4341],{"stroke":2346,"fontFamily":4332,"fontSize":4333},"cmr9","9",[2339,4335,4337],{"transform":4336},"translate(-9.637 3.125)",[2344,4338],{"d":4339,"fill":2341,"stroke":2341,"className":4340,"style":2356},"M-47.368-62.312L-49.455-62.312L-49.455-62.628Q-49.148-62.628-48.956-62.681Q-48.765-62.734-48.765-62.923L-48.765-65.371Q-48.765-65.612-48.836-65.720Q-48.906-65.828-49.040-65.852Q-49.174-65.876-49.455-65.876L-49.455-66.192L-48.115-66.289L-48.115-65.454Q-47.917-65.836-47.563-66.063Q-47.210-66.289-46.783-66.289Q-45.504-66.289-45.504-65.076L-45.504-62.923Q-45.504-62.734-45.313-62.681Q-45.122-62.628-44.815-62.628L-44.815-62.312L-46.902-62.312L-46.902-62.628Q-46.590-62.628-46.399-62.681Q-46.208-62.734-46.208-62.923L-46.208-65.041Q-46.208-65.300-46.252-65.522Q-46.296-65.744-46.441-65.887Q-46.586-66.030-46.845-66.030Q-47.188-66.030-47.469-65.841Q-47.750-65.652-47.906-65.340Q-48.062-65.028-48.062-64.681L-48.062-62.923Q-48.062-62.734-47.869-62.681Q-47.675-62.628-47.368-62.628L-47.368-62.312M-44.358-64.219Q-44.358-64.786-44.085-65.274Q-43.813-65.762-43.342-66.054Q-42.872-66.346-42.305-66.346Q-41.883-66.346-41.508-66.177Q-41.132-66.008-40.855-65.716Q-40.578-65.423-40.420-65.028Q-40.262-64.632-40.262-64.219Q-40.262-63.670-40.541-63.208Q-40.820-62.747-41.288-62.479Q-41.756-62.211-42.305-62.211Q-42.859-62.211-43.329-62.479Q-43.799-62.747-44.078-63.208Q-44.358-63.670-44.358-64.219M-42.305-62.501Q-41.809-62.501-41.532-62.762Q-41.255-63.024-41.163-63.428Q-41.070-63.833-41.070-64.329Q-41.070-64.804-41.169-65.193Q-41.268-65.582-41.541-65.832Q-41.813-66.083-42.305-66.083Q-43.017-66.083-43.281-65.588Q-43.545-65.094-43.545-64.329Q-43.545-63.529-43.290-63.015Q-43.035-62.501-42.305-62.501",[2355],[2339,4342,4343],{"transform":4336},[2344,4344],{"d":4345,"fill":2341,"stroke":2341,"className":4346,"style":2356},"M-37.484-62.211Q-38.029-62.211-38.473-62.494Q-38.917-62.778-39.172-63.250Q-39.426-63.723-39.426-64.254Q-39.426-64.808-39.150-65.274Q-38.873-65.740-38.400-66.014Q-37.928-66.289-37.383-66.289Q-37.049-66.289-36.746-66.157Q-36.442-66.025-36.223-65.788L-36.223-67.638Q-36.223-67.880-36.293-67.988Q-36.363-68.095-36.497-68.119Q-36.631-68.144-36.917-68.144L-36.917-68.460L-35.550-68.557L-35.550-63.129Q-35.550-62.892-35.480-62.784Q-35.410-62.677-35.274-62.653Q-35.137-62.628-34.856-62.628L-34.856-62.312L-36.249-62.211L-36.249-62.760Q-36.500-62.497-36.818-62.354Q-37.137-62.211-37.484-62.211M-37.422-62.475Q-37.053-62.475-36.744-62.686Q-36.434-62.896-36.249-63.239L-36.249-65.371Q-36.421-65.674-36.702-65.852Q-36.983-66.030-37.321-66.030Q-38.011-66.030-38.315-65.509Q-38.618-64.988-38.618-64.246Q-38.618-63.525-38.348-63Q-38.077-62.475-37.422-62.475M-32.285-62.211Q-32.843-62.211-33.316-62.494Q-33.788-62.778-34.063-63.255Q-34.338-63.731-34.338-64.285Q-34.338-64.681-34.195-65.056Q-34.052-65.432-33.795-65.720Q-33.538-66.008-33.180-66.177Q-32.821-66.346-32.417-66.346Q-31.872-66.346-31.501-66.109Q-31.130-65.872-30.943-65.454Q-30.756-65.037-30.756-64.500Q-30.756-64.448-30.780-64.410Q-30.804-64.373-30.853-64.373L-33.525-64.373L-33.525-64.294Q-33.525-63.547-33.213-63.024Q-32.901-62.501-32.202-62.501Q-31.797-62.501-31.477-62.758Q-31.156-63.015-31.033-63.419Q-31.015-63.499-30.932-63.499L-30.853-63.499Q-30.813-63.499-30.785-63.468Q-30.756-63.437-30.756-63.393L-30.756-63.358Q-30.861-63.015-31.083-62.756Q-31.305-62.497-31.619-62.354Q-31.934-62.211-32.285-62.211M-33.516-64.624L-31.402-64.624Q-31.402-64.892-31.455-65.138Q-31.507-65.384-31.628-65.606Q-31.749-65.828-31.947-65.955Q-32.145-66.083-32.417-66.083Q-32.760-66.083-33.013-65.858Q-33.265-65.634-33.390-65.296Q-33.516-64.958-33.516-64.624",[2355],[2339,4348,4349,4356,4362],{"stroke":2346,"fontSize":4333},[2339,4350,4352],{"transform":4351},"translate(22.849 3.125)",[2344,4353],{"d":4354,"fill":2341,"stroke":2341,"className":4355,"style":2356},"M-49.266-62.483Q-49.266-62.536-49.257-62.562L-47.952-67.783Q-47.917-67.933-47.917-68.007Q-47.917-68.144-48.484-68.144Q-48.585-68.144-48.585-68.262Q-48.585-68.319-48.554-68.390Q-48.524-68.460-48.458-68.460L-47.236-68.557L-47.196-68.557Q-47.157-68.539-47.137-68.510Q-47.117-68.482-47.117-68.451L-47.117-68.416L-48.045-64.707Q-47.781-64.817-47.592-64.988Q-47.403-65.160-46.999-65.560Q-46.594-65.959-46.324-66.124Q-46.054-66.289-45.702-66.289Q-45.439-66.289-45.265-66.111Q-45.091-65.933-45.091-65.669Q-45.091-65.428-45.239-65.248Q-45.386-65.067-45.623-65.067Q-45.764-65.067-45.869-65.160Q-45.975-65.252-45.975-65.397Q-45.975-65.599-45.819-65.755Q-45.663-65.911-45.461-65.911Q-45.548-66.030-45.720-66.030Q-46.045-66.030-46.355-65.803Q-46.665-65.577-47.098-65.149Q-47.530-64.720-47.754-64.580Q-47.214-64.518-46.818-64.303Q-46.423-64.087-46.423-63.626Q-46.423-63.542-46.458-63.384Q-46.520-63.116-46.533-62.888Q-46.533-62.475-46.252-62.475Q-45.931-62.475-45.753-62.828Q-45.575-63.182-45.469-63.626Q-45.461-63.657-45.436-63.681Q-45.412-63.705-45.381-63.705L-45.272-63.705Q-45.228-63.705-45.206-63.672Q-45.184-63.639-45.184-63.591Q-45.324-63.033-45.577-62.622Q-45.830-62.211-46.269-62.211Q-46.665-62.211-46.917-62.472Q-47.170-62.734-47.170-63.121Q-47.170-63.217-47.135-63.419Q-47.108-63.512-47.108-63.608Q-47.108-63.841-47.269-63.999Q-47.429-64.158-47.673-64.237Q-47.917-64.316-48.132-64.338L-48.594-62.519Q-48.638-62.382-48.741-62.297Q-48.844-62.211-48.981-62.211Q-49.108-62.211-49.187-62.286Q-49.266-62.360-49.266-62.483",[2355],[2339,4357,4358],{"transform":4351},[2344,4359],{"d":4360,"fill":2341,"stroke":2341,"className":4361,"style":2356},"M-38.175-63.455L-43.981-63.455Q-44.060-63.468-44.110-63.518Q-44.161-63.569-44.161-63.644Q-44.161-63.793-43.981-63.841L-38.175-63.841Q-38.004-63.789-38.004-63.644Q-38.004-63.490-38.175-63.455M-38.175-65.283L-43.981-65.283Q-44.161-65.313-44.161-65.472Q-44.161-65.621-43.981-65.669L-38.175-65.669Q-38.004-65.617-38.004-65.472Q-38.004-65.318-38.175-65.283",[2355],[2339,4363,4364],{"transform":4351},[2344,4365],{"d":4366,"fill":2341,"stroke":2341,"className":4367,"style":2356},"M-35.168-62.114Q-36.293-62.114-36.707-63.011Q-37.120-63.907-37.120-65.182Q-37.120-65.955-36.970-66.654Q-36.821-67.353-36.386-67.829Q-35.951-68.306-35.168-68.306Q-34.391-68.306-33.956-67.827Q-33.521-67.348-33.371-66.652Q-33.222-65.955-33.222-65.182Q-33.222-63.903-33.635-63.009Q-34.048-62.114-35.168-62.114M-35.168-62.374Q-34.650-62.374-34.399-62.885Q-34.149-63.397-34.092-64.008Q-34.035-64.619-34.035-65.327Q-34.035-66.012-34.092-66.572Q-34.149-67.133-34.402-67.590Q-34.654-68.047-35.168-68.047Q-35.573-68.047-35.810-67.770Q-36.047-67.493-36.155-67.052Q-36.263-66.610-36.287-66.217Q-36.311-65.823-36.311-65.327Q-36.311-64.821-36.287-64.393Q-36.263-63.964-36.155-63.481Q-36.047-62.998-35.808-62.686Q-35.568-62.374-35.168-62.374",[2355],[2339,4369,4370,4376,4381],{"stroke":2346,"fontSize":4333},[2339,4371,4373],{"transform":4372},"translate(54.146 3.125)",[2344,4374],{"d":4354,"fill":2341,"stroke":2341,"className":4375,"style":2356},[2355],[2339,4377,4378],{"transform":4372},[2344,4379],{"d":4360,"fill":2341,"stroke":2341,"className":4380,"style":2356},[2355],[2339,4382,4383],{"transform":4372},[2344,4384],{"d":4385,"fill":2341,"stroke":2341,"className":4386,"style":2356},"M-33.573-62.312L-36.605-62.312L-36.605-62.628Q-35.454-62.628-35.454-62.923L-35.454-67.647Q-35.942-67.414-36.663-67.414L-36.663-67.730Q-35.533-67.730-34.971-68.306L-34.826-68.306Q-34.791-68.306-34.758-68.273Q-34.725-68.240-34.725-68.205L-34.725-62.923Q-34.725-62.628-33.573-62.628",[2355],[2339,4388,4389,4395,4400],{"stroke":2346,"fontSize":4333},[2339,4390,4392],{"transform":4391},"translate(85.445 3.125)",[2344,4393],{"d":4354,"fill":2341,"stroke":2341,"className":4394,"style":2356},[2355],[2339,4396,4397],{"transform":4391},[2344,4398],{"d":4360,"fill":2341,"stroke":2341,"className":4399,"style":2356},[2355],[2339,4401,4402],{"transform":4391},[2344,4403],{"d":4404,"fill":2341,"stroke":2341,"className":4405,"style":2356},"M-33.573-62.312L-37.023-62.312L-37.023-62.545Q-37.023-62.558-36.992-62.589L-35.538-64.166Q-35.072-64.663-34.819-64.968Q-34.566-65.274-34.375-65.685Q-34.184-66.096-34.184-66.535Q-34.184-67.124-34.507-67.557Q-34.830-67.990-35.410-67.990Q-35.674-67.990-35.920-67.880Q-36.166-67.770-36.342-67.583Q-36.518-67.396-36.614-67.146L-36.535-67.146Q-36.333-67.146-36.190-67.010Q-36.047-66.874-36.047-66.658Q-36.047-66.452-36.190-66.313Q-36.333-66.175-36.535-66.175Q-36.737-66.175-36.880-66.318Q-37.023-66.460-37.023-66.658Q-37.023-67.120-36.786-67.493Q-36.548-67.867-36.148-68.086Q-35.749-68.306-35.300-68.306Q-34.777-68.306-34.323-68.091Q-33.868-67.875-33.595-67.476Q-33.323-67.076-33.323-66.535Q-33.323-66.140-33.494-65.786Q-33.666-65.432-33.931-65.153Q-34.197-64.874-34.648-64.489Q-35.098-64.105-35.177-64.030L-36.201-63.068L-35.384-63.068Q-34.733-63.068-34.296-63.079Q-33.859-63.090-33.828-63.112Q-33.758-63.195-33.703-63.435Q-33.648-63.674-33.608-63.942L-33.323-63.942",[2355],[2344,4407],{"fill":2346,"d":4408},"M-65.403-32.436h31.298v-19.917h-31.298Z",[2339,4410,4412],{"transform":4411},"translate(-2.312 22.817)",[2344,4413],{"d":4414,"fill":2341,"stroke":2341,"className":4415,"style":2356},"M-49.367-63.679Q-49.367-64.237-49.007-64.650Q-48.647-65.063-48.071-65.335L-48.440-65.568Q-48.743-65.770-48.930-66.100Q-49.117-66.430-49.117-66.786Q-49.117-67.440-48.611-67.873Q-48.106-68.306-47.442-68.306Q-47.043-68.306-46.658-68.146Q-46.274-67.985-46.025-67.680Q-45.777-67.374-45.777-66.957Q-45.777-66.126-46.845-65.568L-46.291-65.221Q-45.944-64.993-45.733-64.624Q-45.522-64.254-45.522-63.841Q-45.522-63.463-45.680-63.145Q-45.838-62.826-46.115-62.593Q-46.392-62.360-46.735-62.237Q-47.078-62.114-47.442-62.114Q-47.908-62.114-48.354-62.301Q-48.800-62.488-49.084-62.842Q-49.367-63.195-49.367-63.679M-48.844-63.679Q-48.844-63.134-48.425-62.767Q-48.005-62.400-47.442-62.400Q-47.113-62.400-46.788-62.532Q-46.462-62.664-46.254-62.918Q-46.045-63.173-46.045-63.516Q-46.045-63.780-46.181-64.004Q-46.317-64.228-46.550-64.382L-47.794-65.164Q-48.255-64.927-48.550-64.540Q-48.844-64.153-48.844-63.679M-48.233-66.434L-47.117-65.731Q-46.893-65.854-46.689-66.043Q-46.484-66.232-46.364-66.465Q-46.243-66.698-46.243-66.957Q-46.243-67.265-46.414-67.515Q-46.586-67.766-46.862-67.906Q-47.139-68.047-47.451-68.047Q-47.900-68.047-48.273-67.801Q-48.647-67.555-48.647-67.128Q-48.647-66.724-48.233-66.434",[2355],[2339,4417,4418,4421],{"stroke":2382},[2344,4419],{"fill":2346,"d":4420},"M-34.105-32.436h31.298v-19.917h-31.298Z",[2339,4422,4424],{"transform":4423},"translate(28.986 22.817)",[2344,4425],{"d":4426,"fill":2382,"stroke":2382,"className":4427,"style":2356},"M-47.056-63.789L-49.495-63.789L-49.495-64.105L-46.669-68.253Q-46.625-68.306-46.559-68.306L-46.405-68.306Q-46.366-68.306-46.333-68.273Q-46.300-68.240-46.300-68.196L-46.300-64.105L-45.399-64.105L-45.399-63.789L-46.300-63.789L-46.300-62.923Q-46.300-62.628-45.399-62.628L-45.399-62.312L-47.952-62.312L-47.952-62.628Q-47.592-62.628-47.324-62.683Q-47.056-62.738-47.056-62.923L-47.056-63.789M-46.999-67.278L-49.161-64.105L-46.999-64.105",[2355],[2344,4429],{"fill":2346,"d":4430},"M-2.807-32.436H28.49v-19.917H-2.807Z",[2339,4432,4434],{"transform":4433},"translate(60.283 22.817)",[2344,4435],{"d":4436,"fill":2341,"stroke":2341,"className":4437,"style":2356},"M-45.847-62.312L-49.297-62.312L-49.297-62.545Q-49.297-62.558-49.266-62.589L-47.812-64.166Q-47.346-64.663-47.093-64.968Q-46.840-65.274-46.649-65.685Q-46.458-66.096-46.458-66.535Q-46.458-67.124-46.781-67.557Q-47.104-67.990-47.684-67.990Q-47.948-67.990-48.194-67.880Q-48.440-67.770-48.616-67.583Q-48.792-67.396-48.888-67.146L-48.809-67.146Q-48.607-67.146-48.464-67.010Q-48.321-66.874-48.321-66.658Q-48.321-66.452-48.464-66.313Q-48.607-66.175-48.809-66.175Q-49.011-66.175-49.154-66.318Q-49.297-66.460-49.297-66.658Q-49.297-67.120-49.060-67.493Q-48.822-67.867-48.422-68.086Q-48.023-68.306-47.574-68.306Q-47.051-68.306-46.597-68.091Q-46.142-67.875-45.869-67.476Q-45.597-67.076-45.597-66.535Q-45.597-66.140-45.768-65.786Q-45.940-65.432-46.205-65.153Q-46.471-64.874-46.922-64.489Q-47.372-64.105-47.451-64.030L-48.475-63.068L-47.658-63.068Q-47.007-63.068-46.570-63.079Q-46.133-63.090-46.102-63.112Q-46.032-63.195-45.977-63.435Q-45.922-63.674-45.882-63.942L-45.597-63.942",[2355],[2339,4439,4440,4443],{"stroke":2382},[2344,4441],{"fill":2346,"d":4442},"M28.49-32.436H59.79v-19.917H28.49Z",[2339,4444,4446],{"transform":4445},"translate(91.582 22.817)",[2344,4447],{"d":4448,"fill":2382,"stroke":2382,"className":4449,"style":2356},"M-45.847-62.312L-48.879-62.312L-48.879-62.628Q-47.728-62.628-47.728-62.923L-47.728-67.647Q-48.216-67.414-48.937-67.414L-48.937-67.730Q-47.807-67.730-47.245-68.306L-47.100-68.306Q-47.065-68.306-47.032-68.273Q-46.999-68.240-46.999-68.205L-46.999-62.923Q-46.999-62.628-45.847-62.628",[2355],[2344,4451],{"fill":2346,"d":4452},"M-65.403-12.52h31.298v-19.916h-31.298Z",[2339,4454,4456],{"transform":4455},"translate(-2.312 42.734)",[2344,4457],{"d":4426,"fill":2341,"stroke":2341,"className":4458,"style":2356},[2355],[2344,4460],{"fill":2346,"d":4461},"M-34.105-12.52h31.298v-19.916h-31.298Z",[2339,4463,4465],{"transform":4464},"translate(28.986 42.734)",[2344,4466],{"d":4436,"fill":2341,"stroke":2341,"className":4467,"style":2356},[2355],[2344,4469],{"fill":2346,"d":4470},"M-2.807-12.52H28.49v-19.916H-2.807Z",[2339,4472,4474],{"transform":4473},"translate(60.283 42.734)",[2344,4475],{"d":4448,"fill":2341,"stroke":2341,"className":4476,"style":2356},[2355],[2344,4478],{"fill":2346,"d":4479},"M28.49-12.52H59.79v-19.916H28.49Z",[2339,4481,4483],{"transform":4482},"translate(91.582 42.734)",[2344,4484],{"d":4448,"fill":2341,"stroke":2341,"className":4485,"style":2356},[2355],[2344,4487],{"fill":2346,"d":4488},"M-65.403 7.398h31.298V-12.52h-31.298Z",[2339,4490,4492],{"transform":4491},"translate(-2.312 62.65)",[2344,4493],{"d":4436,"fill":2341,"stroke":2341,"className":4494,"style":2356},[2355],[2344,4496],{"fill":2346,"d":4497},"M-34.105 7.398h31.298V-12.52h-31.298Z",[2339,4499,4501],{"transform":4500},"translate(28.986 62.65)",[2344,4502],{"d":4448,"fill":2341,"stroke":2341,"className":4503,"style":2356},[2355],[2344,4505],{"fill":2346,"d":4506},"M-2.807 7.398H28.49V-12.52H-2.807Z",[2339,4508,4510],{"transform":4509},"translate(60.283 62.65)",[2344,4511],{"d":4448,"fill":2341,"stroke":2341,"className":4512,"style":2356},[2355],[2344,4514],{"fill":2346,"d":4515},"M28.49 7.398H59.79V-12.52H28.49Z",[2339,4517,4519],{"transform":4518},"translate(91.582 62.65)",[2344,4520],{"d":4448,"fill":2341,"stroke":2341,"className":4521,"style":2356},[2355],[2481,4523,4525,4526,4562,4563,4604],{"className":4524},[2484],"The ",[390,4527,4529],{"className":4528},[393],[390,4530,4532],{"className":4531,"ariaHidden":398},[397],[390,4533,4535,4538,4541,4544,4547,4550,4553,4556,4559],{"className":4534},[402],[390,4536],{"className":4537,"style":586},[406],[390,4539,413],{"className":4540},[411,412],[390,4542,381],{"className":4543},[411,412],[390,4545,1106],{"className":4546},[599],[390,4548,431],{"className":4549,"style":430},[411,412],[390,4551,1113],{"className":4552},[620],[390,4554,1106],{"className":4555},[599],[390,4557,1021],{"className":4558,"style":1020},[411,412],[390,4560,1113],{"className":4561},[620]," table — ",[390,4564,4566],{"className":4565},[393],[390,4567,4569],{"className":4568,"ariaHidden":398},[397],[390,4570,4572,4575],{"className":4571},[402],[390,4573],{"className":4574,"style":1035},[406],[390,4576,4578,4581],{"className":4577},[411],[390,4579,1042],{"className":4580},[411],[390,4582,4584],{"className":4583},[1046],[390,4585,4587],{"className":4586},[1050],[390,4588,4590],{"className":4589},[1054],[390,4591,4593],{"className":4592,"style":1035},[1058],[390,4594,4595,4598],{"style":1061},[390,4596],{"className":4597,"style":1066},[1065],[390,4599,4601],{"className":4600},[1070,1071,1072,1073],[390,4602,1021],{"className":4603,"style":1020},[411,412,1073],"-th ancestors, each column doubled from the last; one query's jump cells in acc",[381,4606,4607,4608,4624,4625,4640,4641,4656,4657,4681,4682,4697,4698,4713,4714,4729,4730,4745,4746,4761,4762,4777,4778,4851,4852,414,4876,4900,4901,4903,4904,4919,4920,4935,4936,4952,4953,4974],{},"Reading row ",[390,4609,4611],{"className":4610},[393],[390,4612,4614],{"className":4613,"ariaHidden":398},[397],[390,4615,4617,4620],{"className":4616},[402],[390,4618],{"className":4619,"style":1448},[406],[390,4621,4623],{"className":4622},[411],"8",": its ",[390,4626,4628],{"className":4627},[393],[390,4629,4631],{"className":4630,"ariaHidden":398},[397],[390,4632,4634,4637],{"className":4633},[402],[390,4635],{"className":4636,"style":1448},[406],[390,4638,1402],{"className":4639},[411],"st ancestor is ",[390,4642,4644],{"className":4643},[393],[390,4645,4647],{"className":4646,"ariaHidden":398},[397],[390,4648,4650,4653],{"className":4649},[402],[390,4651],{"className":4652,"style":1448},[406],[390,4654,2538],{"className":4655},[411]," (",[390,4658,4660],{"className":4659},[393],[390,4661,4663],{"className":4662,"ariaHidden":398},[397],[390,4664,4666,4669,4672,4678],{"className":4665},[402],[390,4667],{"className":4668,"style":822},[406],[390,4670,1021],{"className":4671,"style":1020},[411,412],[390,4673,4675],{"className":4674},[411],[390,4676,850],{"className":4677},[849],[390,4679,1257],{"className":4680},[411],"), its ",[390,4683,4685],{"className":4684},[393],[390,4686,4688],{"className":4687,"ariaHidden":398},[397],[390,4689,4691,4694],{"className":4690},[402],[390,4692],{"className":4693,"style":1448},[406],[390,4695,1042],{"className":4696},[411],"nd is ",[390,4699,4701],{"className":4700},[393],[390,4702,4704],{"className":4703,"ariaHidden":398},[397],[390,4705,4707,4710],{"className":4706},[402],[390,4708],{"className":4709,"style":1448},[406],[390,4711,1042],{"className":4712},[411],", its ",[390,4715,4717],{"className":4716},[393],[390,4718,4720],{"className":4719,"ariaHidden":398},[397],[390,4721,4723,4726],{"className":4722},[402],[390,4724],{"className":4725,"style":1448},[406],[390,4727,2538],{"className":4728},[411],"th\nis ",[390,4731,4733],{"className":4732},[393],[390,4734,4736],{"className":4735,"ariaHidden":398},[397],[390,4737,4739,4742],{"className":4738},[402],[390,4740],{"className":4741,"style":1448},[406],[390,4743,1402],{"className":4744},[411],". To find the ",[390,4747,4749],{"className":4748},[393],[390,4750,4752],{"className":4751,"ariaHidden":398},[397],[390,4753,4755,4758],{"className":4754},[402],[390,4756],{"className":4757,"style":1448},[406],[390,4759,3033],{"className":4760},[411],"th ancestor of ",[390,4763,4765],{"className":4764},[393],[390,4766,4768],{"className":4767,"ariaHidden":398},[397],[390,4769,4771,4774],{"className":4770},[402],[390,4772],{"className":4773,"style":1448},[406],[390,4775,4623],{"className":4776},[411]," we write ",[390,4779,4781],{"className":4780},[393],[390,4782,4784,4802],{"className":4783,"ariaHidden":398},[397],[390,4785,4787,4790,4793,4796,4799],{"className":4786},[402],[390,4788],{"className":4789,"style":1448},[406],[390,4791,3033],{"className":4792},[411],[390,4794],{"className":4795,"style":845},[612],[390,4797,850],{"className":4798},[849],[390,4800],{"className":4801,"style":845},[612],[390,4803,4805,4808,4811],{"className":4804},[402],[390,4806],{"className":4807,"style":3049},[406],[390,4809,3053],{"className":4810},[411],[390,4812,4814,4817],{"className":4813},[411],[390,4815,1402],{"className":4816},[411],[390,4818,4820],{"className":4819},[1046],[390,4821,4823,4843],{"className":4822},[1050,2063],[390,4824,4826,4840],{"className":4825},[1054],[390,4827,4829],{"className":4828,"style":3072},[1058],[390,4830,4831,4834],{"style":3075},[390,4832],{"className":4833,"style":1066},[1065],[390,4835,4837],{"className":4836},[1070,1071,1072,1073],[390,4838,1042],{"className":4839},[411,1073],[390,4841,2087],{"className":4842},[2086],[390,4844,4846],{"className":4845},[1054],[390,4847,4849],{"className":4848,"style":3094},[1058],[390,4850],{}," and jump by the\n",[390,4853,4855],{"className":4854},[393],[390,4856,4858],{"className":4857,"ariaHidden":398},[397],[390,4859,4861,4864,4867,4873],{"className":4860},[402],[390,4862],{"className":4863,"style":822},[406],[390,4865,1021],{"className":4866,"style":1020},[411,412],[390,4868,4870],{"className":4869},[411],[390,4871,850],{"className":4872},[849],[390,4874,1257],{"className":4875},[411],[390,4877,4879],{"className":4878},[393],[390,4880,4882],{"className":4881,"ariaHidden":398},[397],[390,4883,4885,4888,4891,4897],{"className":4884},[402],[390,4886],{"className":4887,"style":822},[406],[390,4889,1021],{"className":4890,"style":1020},[411,412],[390,4892,4894],{"className":4893},[411],[390,4895,850],{"className":4896},[849],[390,4898,1042],{"className":4899},[411]," columns — cells highlighted in ",[734,4902,4198],{}," — climbing ",[390,4905,4907],{"className":4906},[393],[390,4908,4910],{"className":4909,"ariaHidden":398},[397],[390,4911,4913,4916],{"className":4912},[402],[390,4914],{"className":4915,"style":1448},[406],[390,4917,1402],{"className":4918},[411]," then ",[390,4921,4923],{"className":4922},[393],[390,4924,4926],{"className":4925,"ariaHidden":398},[397],[390,4927,4929,4932],{"className":4928},[402],[390,4930],{"className":4931,"style":1448},[406],[390,4933,2538],{"className":4934},[411],"\nedges; on this depth-",[390,4937,4939],{"className":4938},[393],[390,4940,4942],{"className":4941,"ariaHidden":398},[397],[390,4943,4945,4948],{"className":4944},[402],[390,4946],{"className":4947,"style":1448},[406],[390,4949,4951],{"className":4950},[411],"3"," tree that runs off the root, which ",[390,4954,4956],{"className":4955},[393],[390,4957,4959],{"className":4958,"ariaHidden":398},[397],[390,4960,4962,4965],{"className":4961},[402],[390,4963],{"className":4964,"style":822},[406],[390,4966,4968],{"className":4967},[1951,3329],[390,4969,4971],{"className":4970},[411,3333],[390,4972,3337],{"className":4973},[411],"\nreports as nil.",[694,4976,4978],{"id":4977},"application-tree-distance-and-path-queries","Application: tree distance and path queries",[381,4980,4981,4982,553,4997,5012,5013,553,5028,5064,5065,5080],{},"LCA turns a two-vertex path question into arithmetic on depths. The unique path\nfrom ",[390,4983,4985],{"className":4984},[393],[390,4986,4988],{"className":4987,"ariaHidden":398},[397],[390,4989,4991,4994],{"className":4990},[402],[390,4992],{"className":4993,"style":407},[406],[390,4995,413],{"className":4996},[411,412],[390,4998,5000],{"className":4999},[393],[390,5001,5003],{"className":5002,"ariaHidden":398},[397],[390,5004,5006,5009],{"className":5005},[402],[390,5007],{"className":5008,"style":407},[406],[390,5010,431],{"className":5011,"style":430},[411,412]," in a tree goes up from ",[390,5014,5016],{"className":5015},[393],[390,5017,5019],{"className":5018,"ariaHidden":398},[397],[390,5020,5022,5025],{"className":5021},[402],[390,5023],{"className":5024,"style":407},[406],[390,5026,413],{"className":5027},[411,412],[390,5029,5031],{"className":5030},[393],[390,5032,5034],{"className":5033,"ariaHidden":398},[397],[390,5035,5037,5040,5046,5049,5052,5055,5058,5061],{"className":5036},[402],[390,5038],{"className":5039,"style":586},[406],[390,5041,5043],{"className":5042},[590],[390,5044,595],{"className":5045},[411,594],[390,5047,600],{"className":5048},[599],[390,5050,413],{"className":5051},[411,412],[390,5053,608],{"className":5054},[607],[390,5056],{"className":5057,"style":613},[612],[390,5059,431],{"className":5060,"style":430},[411,412],[390,5062,621],{"className":5063},[620]," and back\ndown to ",[390,5066,5068],{"className":5067},[393],[390,5069,5071],{"className":5070,"ariaHidden":398},[397],[390,5072,5074,5077],{"className":5073},[402],[390,5075],{"className":5076,"style":407},[406],[390,5078,431],{"className":5079,"style":430},[411,412],", so its length is",[390,5082,5085],{"className":5083},[5084],"katex-display",[390,5086,5088],{"className":5087},[393],[390,5089,5091,5131,5167,5203],{"className":5090,"ariaHidden":398},[397],[390,5092,5094,5097,5104,5107,5110,5113,5116,5119,5122,5125,5128],{"className":5093},[402],[390,5095],{"className":5096,"style":586},[406],[390,5098,5100],{"className":5099},[590],[390,5101,5103],{"className":5102},[411,594],"dist",[390,5105,600],{"className":5106},[599],[390,5108,413],{"className":5109},[411,412],[390,5111,608],{"className":5112},[607],[390,5114],{"className":5115,"style":613},[612],[390,5117,431],{"className":5118,"style":430},[411,412],[390,5120,621],{"className":5121},[620],[390,5123],{"className":5124,"style":845},[612],[390,5126,850],{"className":5127},[849],[390,5129],{"className":5130,"style":845},[612],[390,5132,5134,5137,5140,5143,5146,5149,5152,5155,5158,5161,5164],{"className":5133},[402],[390,5135],{"className":5136,"style":586},[406],[390,5138,3257],{"className":5139},[411,412],[390,5141,1288],{"className":5142},[411,412],[390,5144,3264],{"className":5145},[411,412],[390,5147,805],{"className":5148},[411,412],[390,5150,1106],{"className":5151},[599],[390,5153,413],{"className":5154},[411,412],[390,5156,1113],{"className":5157},[620],[390,5159],{"className":5160,"style":1546},[612],[390,5162,1842],{"className":5163},[1397],[390,5165],{"className":5166,"style":1546},[612],[390,5168,5170,5173,5176,5179,5182,5185,5188,5191,5194,5197,5200],{"className":5169},[402],[390,5171],{"className":5172,"style":586},[406],[390,5174,3257],{"className":5175},[411,412],[390,5177,1288],{"className":5178},[411,412],[390,5180,3264],{"className":5181},[411,412],[390,5183,805],{"className":5184},[411,412],[390,5186,1106],{"className":5187},[599],[390,5189,431],{"className":5190,"style":430},[411,412],[390,5192,1113],{"className":5193},[620],[390,5195],{"className":5196,"style":1546},[612],[390,5198,1398],{"className":5199},[1397],[390,5201],{"className":5202,"style":1546},[612],[390,5204,5206,5209,5212,5215,5218,5221,5224,5227,5233,5239,5242,5245,5248,5251,5254,5257,5263],{"className":5205},[402],[390,5207],{"className":5208,"style":1504},[406],[390,5210,1042],{"className":5211},[411],[390,5213],{"className":5214,"style":613},[612],[390,5216,3257],{"className":5217},[411,412],[390,5219,1288],{"className":5220},[411,412],[390,5222,3264],{"className":5223},[411,412],[390,5225,805],{"className":5226},[411,412],[390,5228,5230],{"className":5229},[599],[390,5231,1106],{"className":5232},[1517,1518],[390,5234,5236],{"className":5235},[590],[390,5237,595],{"className":5238},[411,594],[390,5240,600],{"className":5241},[599],[390,5243,413],{"className":5244},[411,412],[390,5246,608],{"className":5247},[607],[390,5249],{"className":5250,"style":613},[612],[390,5252,431],{"className":5253,"style":430},[411,412],[390,5255,621],{"className":5256},[620],[390,5258,5260],{"className":5259},[620],[390,5261,1113],{"className":5262},[1517,1518],[390,5264,437],{"className":5265},[411],[381,5267,5268,5269,5293,5294,5327,5328,5390,5391,5412,5413,5416,5417,5416,5420,5423,5424,5496,5497,437],{},"Each query is one LCA plus ",[390,5270,5272],{"className":5271},[393],[390,5273,5275],{"className":5274,"ariaHidden":398},[397],[390,5276,5278,5281,5284,5287,5290],{"className":5277},[402],[390,5279],{"className":5280,"style":586},[406],[390,5282,798],{"className":5283,"style":463},[411,412],[390,5285,600],{"className":5286},[599],[390,5288,1402],{"className":5289},[411],[390,5291,621],{"className":5292},[620]," work, hence ",[390,5295,5297],{"className":5296},[393],[390,5298,5300],{"className":5299,"ariaHidden":398},[397],[390,5301,5303,5306,5309,5312,5318,5321,5324],{"className":5302},[402],[390,5304],{"className":5305,"style":586},[406],[390,5307,798],{"className":5308,"style":463},[411,412],[390,5310,600],{"className":5311},[599],[390,5313,5315],{"className":5314},[590],[390,5316,873],{"className":5317,"style":872},[411,594],[390,5319],{"className":5320,"style":613},[612],[390,5322,880],{"className":5323},[411,412],[390,5325,621],{"className":5326},[620],". The same decomposition\nanswers ",[944,5329,5330,5331,5348,5349,5389],{},"is ",[390,5332,5334],{"className":5333},[393],[390,5335,5337],{"className":5336,"ariaHidden":398},[397],[390,5338,5340,5343],{"className":5339},[402],[390,5341],{"className":5342,"style":407},[406],[390,5344,5347],{"className":5345,"style":5346},[411,412],"margin-right:0.0269em;","w"," on the ",[390,5350,5352],{"className":5351},[393],[390,5353,5355,5380],{"className":5354,"ariaHidden":398},[397],[390,5356,5358,5361,5364,5368,5371,5374,5377],{"className":5357},[402],[390,5359],{"className":5360,"style":2120},[406],[390,5362,413],{"className":5363},[411,412],[390,5365],{"className":5366,"style":5367},[612],"margin-right:-0.1667em;",[390,5369],{"className":5370,"style":1546},[612],[390,5372,1398],{"className":5373},[1397],[390,5375],{"className":5376,"style":5367},[612],[390,5378],{"className":5379,"style":1546},[612],[390,5381,5383,5386],{"className":5382},[402],[390,5384],{"className":5385,"style":407},[406],[390,5387,431],{"className":5388,"style":430},[411,412]," path?",", aggregates a value along the path (split\ninto the two vertical legs), or, combined with ",[390,5392,5394],{"className":5393},[393],[390,5395,5397],{"className":5396,"ariaHidden":398},[397],[390,5398,5400,5403],{"className":5399},[402],[390,5401],{"className":5402,"style":822},[406],[390,5404,5406],{"className":5405},[1951,3329],[390,5407,5409],{"className":5408},[411,3333],[390,5410,3337],{"className":5411},[411],", emits\nstep-by-step ",[734,5414,5415],{},"U","\u002F",[734,5418,5419],{},"L",[734,5421,5422],{},"R"," directions: climb ",[390,5425,5427],{"className":5426},[393],[390,5428,5430,5466],{"className":5429,"ariaHidden":398},[397],[390,5431,5433,5436,5439,5442,5445,5448,5451,5454,5457,5460,5463],{"className":5432},[402],[390,5434],{"className":5435,"style":586},[406],[390,5437,3257],{"className":5438},[411,412],[390,5440,1288],{"className":5441},[411,412],[390,5443,3264],{"className":5444},[411,412],[390,5446,805],{"className":5447},[411,412],[390,5449,1106],{"className":5450},[599],[390,5452,413],{"className":5453},[411,412],[390,5455,1113],{"className":5456},[620],[390,5458],{"className":5459,"style":1546},[612],[390,5461,1398],{"className":5462},[1397],[390,5464],{"className":5465,"style":1546},[612],[390,5467,5469,5472,5475,5478,5481,5484,5487,5493],{"className":5468},[402],[390,5470],{"className":5471,"style":586},[406],[390,5473,3257],{"className":5474},[411,412],[390,5476,1288],{"className":5477},[411,412],[390,5479,3264],{"className":5480},[411,412],[390,5482,805],{"className":5483},[411,412],[390,5485,1106],{"className":5486},[599],[390,5488,5490],{"className":5489},[411,3333],[390,5491,595],{"className":5492},[411],[390,5494,1113],{"className":5495},[620]," steps\nup, then walk the recorded downward path to ",[390,5498,5500],{"className":5499},[393],[390,5501,5503],{"className":5502,"ariaHidden":398},[397],[390,5504,5506,5509],{"className":5505},[402],[390,5507],{"className":5508,"style":407},[406],[390,5510,431],{"className":5511,"style":430},[411,412],[694,5513,5515],{"id":5514},"alternatives","Alternatives",[381,5517,5518,5519],{},"Binary lifting is the most broadly useful LCA method, but two others are worth\nknowing.",[5520,5521,5522],"sup",{},[500,5523,1402],{"href":5524,"ariaDescribedBy":5525,"dataFootnoteRef":376,"id":5527},"#user-content-fn-cprefs",[5526],"footnote-label","user-content-fnref-cprefs",[5529,5530,5531],"ul",{},[5532,5533,5534,5537,5538,5553,5554,5569,5570,5573,5574,5589,5590,5605,5606,5611,5612,5636,5637,3958,5676,5683,5684,5708,5709,5724,5725,5728,5729,5553,5744,5569,5759,5761,5762,5777,5778,5793,5794,5809],"li",{},[434,5535,5536],{},"Euler tour + sparse-table RMQ."," Record the Euler traversal of the tree (each\nnode appended on entry and after each child returns); within it, the LCA of ",[390,5539,5541],{"className":5540},[393],[390,5542,5544],{"className":5543,"ariaHidden":398},[397],[390,5545,5547,5550],{"className":5546},[402],[390,5548],{"className":5549,"style":407},[406],[390,5551,413],{"className":5552},[411,412],"\nand ",[390,5555,5557],{"className":5556},[393],[390,5558,5560],{"className":5559,"ariaHidden":398},[397],[390,5561,5563,5566],{"className":5562},[402],[390,5564],{"className":5565,"style":407},[406],[390,5567,431],{"className":5568,"style":430},[411,412]," is the ",[385,5571,5572],{},"shallowest"," node visited between any occurrence of ",[390,5575,5577],{"className":5576},[393],[390,5578,5580],{"className":5579,"ariaHidden":398},[397],[390,5581,5583,5586],{"className":5582},[402],[390,5584],{"className":5585,"style":407},[406],[390,5587,413],{"className":5588},[411,412]," and of\n",[390,5591,5593],{"className":5592},[393],[390,5594,5596],{"className":5595,"ariaHidden":398},[397],[390,5597,5599,5602],{"className":5598},[402],[390,5600],{"className":5601,"style":407},[406],[390,5603,431],{"className":5604,"style":430},[411,412],". That reduces LCA to a ",[500,5607,5608],{"href":115},[434,5609,5610],{},"range-minimum query"," over the depth array, which a\nsparse table answers in ",[390,5613,5615],{"className":5614},[393],[390,5616,5618],{"className":5617,"ariaHidden":398},[397],[390,5619,5621,5624,5627,5630,5633],{"className":5620},[402],[390,5622],{"className":5623,"style":586},[406],[390,5625,798],{"className":5626,"style":463},[411,412],[390,5628,600],{"className":5629},[599],[390,5631,1402],{"className":5632},[411],[390,5634,621],{"className":5635},[620]," after an ",[390,5638,5640],{"className":5639},[393],[390,5641,5643],{"className":5642,"ariaHidden":398},[397],[390,5644,5646,5649,5652,5655,5658,5661,5667,5670,5673],{"className":5645},[402],[390,5647],{"className":5648,"style":586},[406],[390,5650,798],{"className":5651,"style":463},[411,412],[390,5653,600],{"className":5654},[599],[390,5656,880],{"className":5657},[411,412],[390,5659],{"className":5660,"style":613},[612],[390,5662,5664],{"className":5663},[590],[390,5665,873],{"className":5666,"style":872},[411,594],[390,5668],{"className":5669,"style":613},[612],[390,5671,880],{"className":5672},[411,412],[390,5674,621],{"className":5675},[620],[5520,5677,5678],{},[500,5679,1042],{"href":5680,"ariaDescribedBy":5681,"dataFootnoteRef":376,"id":5682},"#user-content-fn-euler",[5526],"user-content-fnref-euler"," So queries\ndrop to ",[390,5685,5687],{"className":5686},[393],[390,5688,5690],{"className":5689,"ariaHidden":398},[397],[390,5691,5693,5696,5699,5702,5705],{"className":5692},[402],[390,5694],{"className":5695,"style":586},[406],[390,5697,798],{"className":5698,"style":463},[411,412],[390,5700,600],{"className":5701},[599],[390,5703,1402],{"className":5704},[411],[390,5706,621],{"className":5707},[620],", but the structure is static and does not directly give ",[390,5710,5712],{"className":5711},[393],[390,5713,5715],{"className":5714,"ariaHidden":398},[397],[390,5716,5718,5721],{"className":5717},[402],[390,5719],{"className":5720,"style":822},[406],[390,5722,1021],{"className":5723,"style":1020},[411,412],"-th\nancestors.",[5726,5727],"br",{},"The reduction is best seen laid out. Below the tree, the Euler tour writes each\nnode as it is entered and re-entered, with its depth underneath. The LCA of ",[390,5730,5732],{"className":5731},[393],[390,5733,5735],{"className":5734,"ariaHidden":398},[397],[390,5736,5738,5741],{"className":5737},[402],[390,5739],{"className":5740,"style":407},[406],[390,5742,413],{"className":5743},[411,412],[390,5745,5747],{"className":5746},[393],[390,5748,5750],{"className":5749,"ariaHidden":398},[397],[390,5751,5753,5756],{"className":5752},[402],[390,5754],{"className":5755,"style":407},[406],[390,5757,431],{"className":5758,"style":430},[411,412],[434,5760,5572],{}," entry anywhere between an occurrence of ",[390,5763,5765],{"className":5764},[393],[390,5766,5768],{"className":5767,"ariaHidden":398},[397],[390,5769,5771,5774],{"className":5770},[402],[390,5772],{"className":5773,"style":407},[406],[390,5775,413],{"className":5776},[411,412]," and one\nof ",[390,5779,5781],{"className":5780},[393],[390,5782,5784],{"className":5783,"ariaHidden":398},[397],[390,5785,5787,5790],{"className":5786},[402],[390,5788],{"className":5789,"style":407},[406],[390,5791,431],{"className":5792,"style":430},[411,412]," — i.e. the minimum of that depth subarray (shaded), which here is ",[390,5795,5797],{"className":5796},[393],[390,5798,5800],{"className":5799,"ariaHidden":398},[397],[390,5801,5803,5806],{"className":5802},[402],[390,5804],{"className":5805,"style":407},[406],[390,5807,500],{"className":5808},[411,412],":",[2326,5811,5813,6055],{"className":5812},[2329,2330],[2332,5814,5818],{"xmlns":2334,"width":5815,"height":5816,"viewBox":5817},"283.176","185.678","-75 -75 212.382 139.259",[2339,5819,5820,5823,5831,5834,5841,5844,5851,5854,5861,5864,5868,5871,5877,5880,5886,5889,5895,5898,5904,5907,5913,5916,5922,5925,5931,5941,5950,5959,5967,5975,5983,5991,5995,6004,6013],{"stroke":2341,"style":2342},[2344,5821],{"fill":2346,"d":5822},"M61.358-63.534a8.536 8.536 0 1 0-17.072 0 8.536 8.536 0 0 0 17.072 0Zm-8.536 0",[2339,5824,5826],{"transform":5825},"translate(70.59 -46.863)",[2344,5827],{"d":5828,"fill":2341,"stroke":2341,"className":5829,"style":5830},"M-18.950-15.319Q-18.950-15.367-18.943-15.391L-18.431-17.455Q-18.397-17.582-18.397-17.698Q-18.397-17.838-18.450-17.934Q-18.503-18.029-18.626-18.029Q-18.848-18.029-18.949-17.802Q-19.049-17.575-19.159-17.154Q-19.169-17.089-19.231-17.089L-19.340-17.089Q-19.371-17.089-19.395-17.120Q-19.419-17.151-19.419-17.175L-19.419-17.202Q-19.306-17.636-19.125-17.944Q-18.943-18.251-18.612-18.251Q-18.356-18.251-18.144-18.123Q-17.932-17.995-17.870-17.769Q-17.460-18.251-16.893-18.251Q-16.606-18.251-16.380-18.115Q-16.154-17.978-16.154-17.711Q-16.154-17.523-16.274-17.390Q-16.394-17.257-16.575-17.257Q-16.691-17.257-16.773-17.330Q-16.855-17.404-16.855-17.523Q-16.855-17.664-16.764-17.778Q-16.674-17.893-16.541-17.923Q-16.691-18.029-16.906-18.029Q-17.501-18.029-17.898-17.270L-18.383-15.353Q-18.407-15.247-18.501-15.172Q-18.595-15.097-18.711-15.097Q-18.810-15.097-18.880-15.158Q-18.950-15.220-18.950-15.319",[2355],"stroke-width:0.210",[2344,5832],{"fill":2346,"d":5833},"M61.358-39.35a8.536 8.536 0 1 0-17.072 0 8.536 8.536 0 0 0 17.072 0Zm-8.536 0",[2339,5835,5837],{"transform":5836},"translate(70.386 -22.678)",[2344,5838],{"d":5839,"fill":2341,"stroke":2341,"className":5840,"style":5830},"M-18.243-15.097Q-18.567-15.097-18.812-15.254Q-19.056-15.411-19.188-15.676Q-19.319-15.941-19.319-16.266Q-19.319-16.734-19.066-17.197Q-18.814-17.660-18.390-17.956Q-17.966-18.251-17.494-18.251Q-17.279-18.251-17.093-18.147Q-16.906-18.043-16.787-17.858Q-16.763-17.971-16.669-18.045Q-16.575-18.118-16.459-18.118Q-16.356-18.118-16.288-18.057Q-16.219-17.995-16.219-17.896Q-16.219-17.838-16.226-17.811L-16.708-15.893Q-16.735-15.736-16.735-15.647Q-16.735-15.520-16.684-15.420Q-16.633-15.319-16.513-15.319Q-16.291-15.319-16.178-15.572Q-16.066-15.825-15.980-16.194Q-15.956-16.255-15.905-16.255L-15.792-16.255Q-15.758-16.255-15.736-16.226Q-15.713-16.197-15.713-16.173Q-15.713-16.160-15.720-16.146Q-15.983-15.097-16.527-15.097Q-16.776-15.097-16.985-15.220Q-17.193-15.343-17.262-15.572Q-17.737-15.097-18.243-15.097M-18.229-15.319Q-17.956-15.319-17.704-15.503Q-17.453-15.688-17.262-15.955L-16.893-17.435Q-16.930-17.595-17.011-17.732Q-17.091-17.869-17.217-17.949Q-17.344-18.029-17.508-18.029Q-17.716-18.029-17.903-17.905Q-18.089-17.780-18.227-17.588Q-18.366-17.397-18.451-17.195Q-18.564-16.901-18.648-16.556Q-18.732-16.211-18.732-15.961Q-18.732-15.705-18.603-15.512Q-18.475-15.319-18.229-15.319",[2355],[2344,5842],{"fill":2346,"d":5843},"M44.428-15.165a8.536 8.536 0 1 0-17.071 0 8.536 8.536 0 0 0 17.071 0Zm-8.536 0",[2339,5845,5847],{"transform":5846},"translate(53.261 1.507)",[2344,5848],{"d":5849,"fill":2341,"stroke":2341,"className":5850,"style":5830},"M-18.745-15.985Q-18.745-16.296-18.638-16.616Q-18.530-16.936-18.318-17.455Q-18.243-17.657-18.243-17.797Q-18.243-17.896-18.282-17.963Q-18.321-18.029-18.410-18.029Q-18.691-18.029-18.880-17.758Q-19.070-17.486-19.159-17.154Q-19.169-17.089-19.231-17.089L-19.340-17.089Q-19.371-17.089-19.395-17.120Q-19.419-17.151-19.419-17.175L-19.419-17.202Q-19.350-17.462-19.210-17.699Q-19.070-17.937-18.860-18.094Q-18.650-18.251-18.397-18.251Q-18.215-18.251-18.060-18.180Q-17.904-18.108-17.807-17.973Q-17.710-17.838-17.710-17.657Q-17.710-17.540-17.757-17.404Q-17.973-16.874-18.086-16.532Q-18.198-16.190-18.198-15.879Q-18.198-15.637-18.084-15.478Q-17.969-15.319-17.730-15.319Q-17.487-15.319-17.248-15.493Q-17.146-15.572-17.019-15.712Q-16.893-15.852-16.876-15.941L-16.380-17.923Q-16.349-18.036-16.257-18.110Q-16.165-18.183-16.052-18.183Q-15.949-18.183-15.878-18.120Q-15.806-18.057-15.806-17.957Q-15.806-17.930-15.819-17.875L-16.318-15.893Q-16.346-15.736-16.346-15.647Q-16.346-15.520-16.293-15.420Q-16.240-15.319-16.120-15.319Q-15.997-15.319-15.908-15.411Q-15.819-15.503-15.763-15.630Q-15.707-15.756-15.657-15.932Q-15.608-16.108-15.590-16.194Q-15.560-16.255-15.512-16.255L-15.399-16.255Q-15.365-16.255-15.344-16.230Q-15.324-16.204-15.324-16.173Q-15.324-16.160-15.331-16.146Q-15.587-15.097-16.134-15.097Q-16.373-15.097-16.580-15.213Q-16.787-15.329-16.862-15.544Q-17.262-15.097-17.744-15.097Q-18.191-15.097-18.468-15.321Q-18.745-15.544-18.745-15.985",[2355],[2344,5852],{"fill":2346,"d":5853},"M78.287-15.165a8.536 8.536 0 1 0-17.072 0 8.536 8.536 0 0 0 17.072 0Zm-8.536 0",[2339,5855,5857],{"transform":5856},"translate(87.358 1.507)",[2344,5858],{"d":5859,"fill":2341,"stroke":2341,"className":5860,"style":5830},"M-18.745-16.013Q-18.745-16.225-18.684-16.457Q-18.622-16.689-18.511-16.970Q-18.400-17.250-18.318-17.455Q-18.243-17.657-18.243-17.797Q-18.243-17.896-18.282-17.963Q-18.321-18.029-18.410-18.029Q-18.691-18.029-18.880-17.758Q-19.070-17.486-19.159-17.154Q-19.169-17.089-19.231-17.089L-19.340-17.089Q-19.371-17.089-19.395-17.120Q-19.419-17.151-19.419-17.175L-19.419-17.202Q-19.350-17.462-19.210-17.699Q-19.070-17.937-18.860-18.094Q-18.650-18.251-18.397-18.251Q-18.215-18.251-18.060-18.180Q-17.904-18.108-17.807-17.973Q-17.710-17.838-17.710-17.657Q-17.710-17.540-17.757-17.404Q-17.986-16.840-18.089-16.532Q-18.191-16.225-18.191-15.920Q-18.191-15.644-18.045-15.481Q-17.898-15.319-17.628-15.319Q-17.241-15.319-16.920-15.753Q-16.800-15.910-16.674-16.160Q-16.547-16.409-16.464-16.669Q-16.380-16.929-16.380-17.103Q-16.380-17.308-16.441-17.402Q-16.503-17.496-16.631-17.634Q-16.759-17.773-16.759-17.869Q-16.759-17.968-16.701-18.057Q-16.643-18.145-16.553-18.202Q-16.462-18.258-16.359-18.258Q-16.168-18.258-16.081-18.089Q-15.994-17.920-15.994-17.705Q-15.994-17.376-16.108-16.934Q-16.223-16.491-16.441-16.067Q-16.660-15.644-16.966-15.370Q-17.272-15.097-17.634-15.097Q-18.123-15.097-18.434-15.319Q-18.745-15.541-18.745-16.013",[2355],[2344,5862],{"fill":2346,"d":5863},"M52.822-54.798v6.713M47.812-32.193l-6.91 9.872M57.831-32.193l6.91 9.872",[2344,5865],{"fill":5866,"stroke":2346,"d":5867},"var(--tk-soft-accent)","M17.754 23.247V3.329H87.89v19.918ZM87.89 3.329",[2344,5869],{"fill":2346,"d":5870},"M-28.269 21.824h17.072V4.752h-17.072Z",[2339,5872,5874],{"transform":5873},"translate(-1.964 29.96)",[2344,5875],{"d":5828,"fill":2341,"stroke":2341,"className":5876,"style":5830},[2355],[2344,5878],{"fill":2346,"d":5879},"M-4.084 21.824h17.072V4.752H-4.084Z",[2339,5881,5883],{"transform":5882},"translate(22.016 29.96)",[2344,5884],{"d":5839,"fill":2341,"stroke":2341,"className":5885,"style":5830},[2355],[2344,5887],{"fill":2346,"d":5888},"M20.101 21.824h17.072V4.752H20.1Z",[2339,5890,5892],{"transform":5891},"translate(46.006 29.96)",[2344,5893],{"d":5849,"fill":2341,"stroke":2341,"className":5894,"style":5830},[2355],[2344,5896],{"fill":2346,"d":5897},"M44.286 21.824h17.072V4.752H44.286Z",[2339,5899,5901],{"transform":5900},"translate(70.386 29.96)",[2344,5902],{"d":5839,"fill":2341,"stroke":2341,"className":5903,"style":5830},[2355],[2344,5905],{"fill":2346,"d":5906},"M68.47 21.824h17.072V4.752H68.471Z",[2339,5908,5910],{"transform":5909},"translate(94.614 29.96)",[2344,5911],{"d":5859,"fill":2341,"stroke":2341,"className":5912,"style":5830},[2355],[2344,5914],{"fill":2346,"d":5915},"M92.656 21.824h17.071V4.752H92.656Z",[2339,5917,5919],{"transform":5918},"translate(118.755 29.96)",[2344,5920],{"d":5839,"fill":2341,"stroke":2341,"className":5921,"style":5830},[2355],[2344,5923],{"fill":2346,"d":5924},"M116.84 21.824h17.072V4.752H116.84Z",[2339,5926,5928],{"transform":5927},"translate(143.145 29.96)",[2344,5929],{"d":5828,"fill":2341,"stroke":2341,"className":5930,"style":5830},[2355],[2339,5932,5934],{"fill":5933,"stroke":5933},"gray",[2339,5935,5937],{"transform":5936},"translate(-1.993 52.048)",[2344,5938],{"d":5939,"fill":5933,"stroke":5933,"className":5940,"style":5830},"M-17.744-15.025Q-18.379-15.025-18.743-15.370Q-19.108-15.715-19.243-16.240Q-19.378-16.765-19.378-17.390Q-19.378-18.415-19.022-19.114Q-18.667-19.813-17.744-19.813Q-16.817-19.813-16.465-19.114Q-16.113-18.415-16.113-17.390Q-16.113-16.765-16.248-16.240Q-16.383-15.715-16.746-15.370Q-17.108-15.025-17.744-15.025M-17.744-15.250Q-17.306-15.250-17.093-15.625Q-16.879-15.999-16.829-16.466Q-16.780-16.932-16.780-17.510Q-16.780-18.063-16.829-18.491Q-16.879-18.918-17.091-19.253Q-17.303-19.588-17.744-19.588Q-18.086-19.588-18.289-19.381Q-18.492-19.174-18.579-18.862Q-18.667-18.549-18.689-18.233Q-18.711-17.916-18.711-17.510Q-18.711-17.093-18.689-16.751Q-18.667-16.409-18.578-16.061Q-18.489-15.712-18.284-15.481Q-18.079-15.250-17.744-15.250",[2355],[2339,5942,5943],{"fill":5933,"stroke":5933},[2339,5944,5946],{"transform":5945},"translate(22.192 52.048)",[2344,5947],{"d":5948,"fill":5933,"stroke":5933,"className":5949,"style":5830},"M-16.407-15.165L-18.937-15.165L-18.937-15.445Q-17.969-15.445-17.969-15.654L-17.969-19.273Q-18.362-19.085-18.984-19.085L-18.984-19.366Q-18.567-19.366-18.203-19.467Q-17.839-19.567-17.583-19.813L-17.457-19.813Q-17.392-19.796-17.375-19.728L-17.375-15.654Q-17.375-15.445-16.407-15.445",[2355],[2339,5951,5952],{"fill":5933,"stroke":5933},[2339,5953,5955],{"transform":5954},"translate(46.377 52.048)",[2344,5956],{"d":5957,"fill":5933,"stroke":5933,"className":5958,"style":5830},"M-16.407-15.165L-19.292-15.165L-19.292-15.367Q-19.292-15.397-19.265-15.425L-18.017-16.642Q-17.945-16.717-17.903-16.759Q-17.860-16.802-17.781-16.881Q-17.368-17.294-17.137-17.652Q-16.906-18.009-16.906-18.433Q-16.906-18.665-16.985-18.868Q-17.064-19.072-17.205-19.222Q-17.347-19.373-17.542-19.453Q-17.737-19.533-17.969-19.533Q-18.280-19.533-18.538-19.374Q-18.796-19.215-18.926-18.938L-18.906-18.938Q-18.738-18.938-18.631-18.827Q-18.523-18.716-18.523-18.552Q-18.523-18.395-18.632-18.282Q-18.742-18.169-18.906-18.169Q-19.066-18.169-19.179-18.282Q-19.292-18.395-19.292-18.552Q-19.292-18.928-19.084-19.215Q-18.875-19.502-18.540-19.658Q-18.205-19.813-17.850-19.813Q-17.426-19.813-17.046-19.655Q-16.667-19.496-16.433-19.179Q-16.199-18.863-16.199-18.433Q-16.199-18.122-16.339-17.853Q-16.479-17.585-16.684-17.380Q-16.889-17.175-17.252-16.893Q-17.614-16.611-17.723-16.515L-18.578-15.787L-17.935-15.787Q-17.672-15.787-17.383-15.789Q-17.094-15.790-16.876-15.799Q-16.657-15.808-16.640-15.825Q-16.578-15.890-16.541-16.057Q-16.503-16.225-16.465-16.467L-16.199-16.467",[2355],[2339,5960,5961],{"fill":5933,"stroke":5933},[2339,5962,5964],{"transform":5963},"translate(70.561 52.048)",[2344,5965],{"d":5948,"fill":5933,"stroke":5933,"className":5966,"style":5830},[2355],[2339,5968,5969],{"fill":5933,"stroke":5933},[2339,5970,5972],{"transform":5971},"translate(94.746 52.048)",[2344,5973],{"d":5957,"fill":5933,"stroke":5933,"className":5974,"style":5830},[2355],[2339,5976,5977],{"fill":5933,"stroke":5933},[2339,5978,5980],{"transform":5979},"translate(118.931 52.048)",[2344,5981],{"d":5948,"fill":5933,"stroke":5933,"className":5982,"style":5830},[2355],[2339,5984,5985],{"fill":5933,"stroke":5933},[2339,5986,5988],{"transform":5987},"translate(143.116 52.048)",[2344,5989],{"d":5939,"fill":5933,"stroke":5933,"className":5990,"style":5830},[2355],[2339,5992,5993],{"stroke":2382,"style":4034},[2344,5994],{"fill":2346,"d":5897},[2339,5996,5997],{"fill":5933,"stroke":5933},[2339,5998,6000],{"transform":5999},"translate(-39.899 30.606)",[2344,6001],{"d":6002,"fill":5933,"stroke":5933,"className":6003,"style":5830},"M-18.892-16.006L-18.892-17.903L-19.531-17.903L-19.531-18.125Q-19.213-18.125-18.996-18.335Q-18.779-18.545-18.679-18.855Q-18.578-19.164-18.578-19.472L-18.311-19.472L-18.311-18.183L-17.234-18.183L-17.234-17.903L-18.311-17.903L-18.311-16.019Q-18.311-15.743-18.207-15.544Q-18.103-15.346-17.843-15.346Q-17.686-15.346-17.580-15.450Q-17.474-15.555-17.424-15.708Q-17.375-15.862-17.375-16.019L-17.375-16.433L-17.108-16.433L-17.108-16.006Q-17.108-15.780-17.207-15.570Q-17.306-15.360-17.491-15.228Q-17.675-15.097-17.904-15.097Q-18.342-15.097-18.617-15.334Q-18.892-15.572-18.892-16.006M-16.339-16.648Q-16.339-16.990-16.204-17.289Q-16.069-17.588-15.830-17.812Q-15.590-18.036-15.273-18.161Q-14.955-18.286-14.623-18.286Q-14.179-18.286-13.779-18.070Q-13.379-17.855-13.145-17.477Q-12.911-17.100-12.911-16.648Q-12.911-16.307-13.053-16.023Q-13.194-15.739-13.439-15.532Q-13.683-15.326-13.993-15.211Q-14.302-15.097-14.623-15.097Q-15.054-15.097-15.455-15.298Q-15.857-15.500-16.098-15.852Q-16.339-16.204-16.339-16.648M-14.623-15.346Q-14.022-15.346-13.798-15.724Q-13.574-16.102-13.574-16.734Q-13.574-17.346-13.808-17.705Q-14.042-18.063-14.623-18.063Q-15.676-18.063-15.676-16.734Q-15.676-16.102-15.450-15.724Q-15.225-15.346-14.623-15.346M-11.742-15.999L-11.742-17.503Q-11.742-17.773-11.849-17.834Q-11.957-17.896-12.268-17.896L-12.268-18.176L-11.161-18.251L-11.161-16.019L-11.161-15.999Q-11.161-15.719-11.109-15.575Q-11.058-15.432-10.916-15.375Q-10.775-15.319-10.487-15.319Q-10.234-15.319-10.029-15.459Q-9.824-15.599-9.708-15.825Q-9.592-16.050-9.592-16.300L-9.592-17.503Q-9.592-17.773-9.700-17.834Q-9.807-17.896-10.118-17.896L-10.118-18.176L-9.011-18.251L-9.011-15.838Q-9.011-15.647-8.958-15.565Q-8.905-15.483-8.804-15.464Q-8.703-15.445-8.488-15.445L-8.488-15.165L-9.565-15.097L-9.565-15.661Q-9.674-15.479-9.819-15.356Q-9.964-15.233-10.151-15.165Q-10.337-15.097-10.539-15.097Q-11.742-15.097-11.742-15.999M-6.150-15.165L-7.886-15.165L-7.886-15.445Q-7.657-15.445-7.509-15.479Q-7.360-15.514-7.360-15.654L-7.360-17.503Q-7.360-17.773-7.468-17.834Q-7.575-17.896-7.886-17.896L-7.886-18.176L-6.858-18.251L-6.858-17.544Q-6.728-17.852-6.485-18.051Q-6.242-18.251-5.924-18.251Q-5.706-18.251-5.535-18.127Q-5.364-18.002-5.364-17.790Q-5.364-17.653-5.463-17.554Q-5.562-17.455-5.695-17.455Q-5.832-17.455-5.931-17.554Q-6.030-17.653-6.030-17.790Q-6.030-17.930-5.931-18.029Q-6.222-18.029-6.422-17.833Q-6.622-17.636-6.714-17.342Q-6.806-17.048-6.806-16.768L-6.806-15.654Q-6.806-15.445-6.150-15.445L-6.150-15.165M-4.379-15.585Q-4.379-15.753-4.256-15.876Q-4.133-15.999-3.959-15.999Q-3.792-15.999-3.669-15.876Q-3.546-15.753-3.546-15.585Q-3.546-15.411-3.669-15.288Q-3.792-15.165-3.959-15.165Q-4.133-15.165-4.256-15.288Q-4.379-15.411-4.379-15.585M-4.379-17.769Q-4.379-17.937-4.256-18.060Q-4.133-18.183-3.959-18.183Q-3.792-18.183-3.669-18.060Q-3.546-17.937-3.546-17.769Q-3.546-17.595-3.669-17.472Q-3.792-17.349-3.959-17.349Q-4.133-17.349-4.256-17.472Q-4.379-17.595-4.379-17.769",[2355],[2339,6005,6006],{"fill":5933,"stroke":5933},[2339,6007,6009],{"transform":6008},"translate(-42.538 51.542)",[2344,6010],{"d":6011,"fill":5933,"stroke":5933,"className":6012,"style":5830},"M-19.419-16.676Q-19.419-17.014-19.278-17.305Q-19.138-17.595-18.894-17.809Q-18.650-18.022-18.345-18.137Q-18.041-18.251-17.716-18.251Q-17.446-18.251-17.183-18.152Q-16.920-18.053-16.729-17.875L-16.729-19.273Q-16.729-19.543-16.836-19.605Q-16.944-19.666-17.255-19.666L-17.255-19.947L-16.178-20.022L-16.178-15.838Q-16.178-15.650-16.124-15.567Q-16.069-15.483-15.968-15.464Q-15.867-15.445-15.652-15.445L-15.652-15.165L-16.759-15.097L-16.759-15.514Q-17.176-15.097-17.802-15.097Q-18.233-15.097-18.605-15.309Q-18.978-15.520-19.198-15.881Q-19.419-16.242-19.419-16.676M-17.744-15.319Q-17.535-15.319-17.349-15.391Q-17.163-15.462-17.009-15.599Q-16.855-15.736-16.759-15.914L-16.759-17.523Q-16.845-17.670-16.990-17.790Q-17.135-17.910-17.305-17.969Q-17.474-18.029-17.655-18.029Q-18.215-18.029-18.484-17.640Q-18.752-17.250-18.752-16.669Q-18.752-16.098-18.518-15.708Q-18.284-15.319-17.744-15.319M-15.044-16.700Q-15.044-17.021-14.919-17.310Q-14.794-17.599-14.568-17.822Q-14.343-18.046-14.047-18.166Q-13.752-18.286-13.434-18.286Q-13.106-18.286-12.844-18.186Q-12.583-18.087-12.407-17.905Q-12.231-17.722-12.137-17.464Q-12.043-17.206-12.043-16.874Q-12.043-16.782-12.125-16.761L-14.380-16.761L-14.380-16.700Q-14.380-16.112-14.097-15.729Q-13.813-15.346-13.246-15.346Q-12.924-15.346-12.656-15.539Q-12.388-15.732-12.299-16.047Q-12.292-16.088-12.217-16.102L-12.125-16.102Q-12.043-16.078-12.043-16.006Q-12.043-15.999-12.049-15.972Q-12.162-15.575-12.533-15.336Q-12.904-15.097-13.328-15.097Q-13.765-15.097-14.165-15.305Q-14.565-15.514-14.804-15.881Q-15.044-16.248-15.044-16.700M-14.374-16.970L-12.559-16.970Q-12.559-17.247-12.656-17.499Q-12.754-17.752-12.952-17.908Q-13.150-18.063-13.434-18.063Q-13.711-18.063-13.924-17.905Q-14.138-17.746-14.256-17.491Q-14.374-17.236-14.374-16.970M-9.811-13.808L-11.441-13.808L-11.441-14.088Q-11.212-14.088-11.063-14.123Q-10.915-14.157-10.915-14.297L-10.915-17.643Q-10.915-17.814-11.051-17.855Q-11.188-17.896-11.441-17.896L-11.441-18.176L-10.361-18.251L-10.361-17.845Q-10.139-18.046-9.852-18.149Q-9.565-18.251-9.257-18.251Q-8.830-18.251-8.466-18.038Q-8.102-17.824-7.888-17.460Q-7.674-17.096-7.674-16.676Q-7.674-16.231-7.914-15.867Q-8.153-15.503-8.546-15.300Q-8.939-15.097-9.383-15.097Q-9.650-15.097-9.898-15.197Q-10.146-15.298-10.334-15.479L-10.334-14.297Q-10.334-14.160-10.185-14.124Q-10.036-14.088-9.811-14.088L-9.811-13.808M-10.334-17.496L-10.334-15.886Q-10.200-15.633-9.958-15.476Q-9.715-15.319-9.438-15.319Q-9.110-15.319-8.857-15.520Q-8.604-15.722-8.471-16.040Q-8.337-16.358-8.337-16.676Q-8.337-16.905-8.402-17.134Q-8.467-17.363-8.596-17.561Q-8.724-17.759-8.919-17.879Q-9.113-17.998-9.346-17.998Q-9.640-17.998-9.908-17.869Q-10.176-17.739-10.334-17.496M-6.512-16.006L-6.512-17.903L-7.151-17.903L-7.151-18.125Q-6.834-18.125-6.617-18.335Q-6.400-18.545-6.299-18.855Q-6.198-19.164-6.198-19.472L-5.931-19.472L-5.931-18.183L-4.855-18.183L-4.855-17.903L-5.931-17.903L-5.931-16.019Q-5.931-15.743-5.827-15.544Q-5.723-15.346-5.463-15.346Q-5.306-15.346-5.200-15.450Q-5.094-15.555-5.044-15.708Q-4.995-15.862-4.995-16.019L-4.995-16.433L-4.728-16.433L-4.728-16.006Q-4.728-15.780-4.827-15.570Q-4.926-15.360-5.111-15.228Q-5.296-15.097-5.525-15.097Q-5.962-15.097-6.237-15.334Q-6.512-15.572-6.512-16.006M-2.236-15.165L-3.870-15.165L-3.870-15.445Q-3.641-15.445-3.493-15.479Q-3.344-15.514-3.344-15.654L-3.344-19.273Q-3.344-19.543-3.452-19.605Q-3.559-19.666-3.870-19.666L-3.870-19.947L-2.790-20.022L-2.790-17.636Q-2.684-17.821-2.506-17.963Q-2.329-18.104-2.120-18.178Q-1.912-18.251-1.686-18.251Q-1.180-18.251-0.897-18.028Q-0.613-17.804-0.613-17.308L-0.613-15.654Q-0.613-15.517-0.464-15.481Q-0.316-15.445-0.090-15.445L-0.090-15.165L-1.720-15.165L-1.720-15.445Q-1.491-15.445-1.343-15.479Q-1.194-15.514-1.194-15.654L-1.194-17.294Q-1.194-17.629-1.314-17.829Q-1.433-18.029-1.748-18.029Q-2.018-18.029-2.252-17.893Q-2.486-17.756-2.624-17.522Q-2.763-17.288-2.763-17.014L-2.763-15.654Q-2.763-15.517-2.612-15.481Q-2.462-15.445-2.236-15.445L-2.236-15.165M0.898-15.585Q0.898-15.753 1.021-15.876Q1.144-15.999 1.318-15.999Q1.486-15.999 1.609-15.876Q1.732-15.753 1.732-15.585Q1.732-15.411 1.609-15.288Q1.486-15.165 1.318-15.165Q1.144-15.165 1.021-15.288Q0.898-15.411 0.898-15.585M0.898-17.769Q0.898-17.937 1.021-18.060Q1.144-18.183 1.318-18.183Q1.486-18.183 1.609-18.060Q1.732-17.937 1.732-17.769Q1.732-17.595 1.609-17.472Q1.486-17.349 1.318-17.349Q1.144-17.349 1.021-17.472Q0.898-17.595 0.898-17.769",[2355],[2339,6014,6015],{"fill":2382,"stroke":2382},[2339,6016,6018,6025,6031,6037,6043,6049],{"fill":2382,"stroke":2346,"fontSize":6017},"7",[2339,6019,6021],{"transform":6020},"translate(36.645 71.46)",[2344,6022],{"d":6023,"fill":2382,"stroke":2382,"className":6024,"style":5830},"M-17.737-15.165L-19.371-15.165L-19.371-15.445Q-19.142-15.445-18.993-15.479Q-18.844-15.514-18.844-15.654L-18.844-17.503Q-18.844-17.773-18.952-17.834Q-19.060-17.896-19.371-17.896L-19.371-18.176L-18.311-18.251L-18.311-17.602Q-18.140-17.910-17.836-18.081Q-17.532-18.251-17.187-18.251Q-16.787-18.251-16.510-18.111Q-16.233-17.971-16.148-17.623Q-15.980-17.916-15.681-18.084Q-15.382-18.251-15.037-18.251Q-14.531-18.251-14.247-18.028Q-13.963-17.804-13.963-17.308L-13.963-15.654Q-13.963-15.517-13.815-15.481Q-13.666-15.445-13.441-15.445L-13.441-15.165L-15.071-15.165L-15.071-15.445Q-14.845-15.445-14.695-15.481Q-14.545-15.517-14.545-15.654L-14.545-17.294Q-14.545-17.629-14.664-17.829Q-14.784-18.029-15.098-18.029Q-15.368-18.029-15.602-17.893Q-15.837-17.756-15.975-17.522Q-16.113-17.288-16.113-17.014L-16.113-15.654Q-16.113-15.517-15.965-15.481Q-15.816-15.445-15.590-15.445L-15.590-15.165L-17.221-15.165L-17.221-15.445Q-16.992-15.445-16.843-15.479Q-16.694-15.514-16.694-15.654L-16.694-17.294Q-16.694-17.629-16.814-17.829Q-16.934-18.029-17.248-18.029Q-17.518-18.029-17.752-17.893Q-17.986-17.756-18.125-17.522Q-18.263-17.288-18.263-17.014L-18.263-15.654Q-18.263-15.517-18.113-15.481Q-17.962-15.445-17.737-15.445L-17.737-15.165M-11.236-15.165L-12.788-15.165L-12.788-15.445Q-12.562-15.445-12.413-15.479Q-12.265-15.514-12.265-15.654L-12.265-17.503Q-12.265-17.691-12.313-17.775Q-12.360-17.858-12.458-17.877Q-12.555-17.896-12.767-17.896L-12.767-18.176L-11.711-18.251L-11.711-15.654Q-11.711-15.514-11.579-15.479Q-11.448-15.445-11.236-15.445L-11.236-15.165M-12.507-19.472Q-12.507-19.643-12.384-19.762Q-12.261-19.882-12.090-19.882Q-11.923-19.882-11.800-19.762Q-11.677-19.643-11.677-19.472Q-11.677-19.297-11.800-19.174Q-11.923-19.051-12.090-19.051Q-12.261-19.051-12.384-19.174Q-12.507-19.297-12.507-19.472M-8.908-15.165L-10.542-15.165L-10.542-15.445Q-10.313-15.445-10.164-15.479Q-10.016-15.514-10.016-15.654L-10.016-17.503Q-10.016-17.773-10.123-17.834Q-10.231-17.896-10.542-17.896L-10.542-18.176L-9.483-18.251L-9.483-17.602Q-9.312-17.910-9.007-18.081Q-8.703-18.251-8.358-18.251Q-7.852-18.251-7.568-18.028Q-7.285-17.804-7.285-17.308L-7.285-15.654Q-7.285-15.517-7.136-15.481Q-6.987-15.445-6.762-15.445L-6.762-15.165L-8.392-15.165L-8.392-15.445Q-8.163-15.445-8.014-15.479Q-7.866-15.514-7.866-15.654L-7.866-17.294Q-7.866-17.629-7.985-17.829Q-8.105-18.029-8.420-18.029Q-8.690-18.029-8.924-17.893Q-9.158-17.756-9.296-17.522Q-9.435-17.288-9.435-17.014L-9.435-15.654Q-9.435-15.517-9.284-15.481Q-9.134-15.445-8.908-15.445",[2355],[2339,6026,6027],{"transform":6020},[2344,6028],{"d":6029,"fill":2382,"stroke":2382,"className":6030,"style":5830},"M-3.474-16.676Q-3.474-17.014-3.333-17.305Q-3.193-17.595-2.949-17.809Q-2.705-18.022-2.400-18.137Q-2.096-18.251-1.771-18.251Q-1.501-18.251-1.238-18.152Q-0.975-18.053-0.784-17.875L-0.784-19.273Q-0.784-19.543-0.891-19.605Q-0.999-19.666-1.310-19.666L-1.310-19.947L-0.233-20.022L-0.233-15.838Q-0.233-15.650-0.179-15.567Q-0.124-15.483-0.023-15.464Q0.078-15.445 0.293-15.445L0.293-15.165L-0.814-15.097L-0.814-15.514Q-1.231-15.097-1.857-15.097Q-2.288-15.097-2.660-15.309Q-3.033-15.520-3.253-15.881Q-3.474-16.242-3.474-16.676M-1.799-15.319Q-1.590-15.319-1.404-15.391Q-1.218-15.462-1.064-15.599Q-0.910-15.736-0.814-15.914L-0.814-17.523Q-0.900-17.670-1.045-17.790Q-1.190-17.910-1.360-17.969Q-1.529-18.029-1.710-18.029Q-2.270-18.029-2.539-17.640Q-2.807-17.250-2.807-16.669Q-2.807-16.098-2.573-15.708Q-2.339-15.319-1.799-15.319M0.901-16.700Q0.901-17.021 1.026-17.310Q1.151-17.599 1.377-17.822Q1.602-18.046 1.898-18.166Q2.193-18.286 2.511-18.286Q2.839-18.286 3.101-18.186Q3.362-18.087 3.538-17.905Q3.714-17.722 3.808-17.464Q3.902-17.206 3.902-16.874Q3.902-16.782 3.820-16.761L1.565-16.761L1.565-16.700Q1.565-16.112 1.848-15.729Q2.132-15.346 2.699-15.346Q3.021-15.346 3.289-15.539Q3.557-15.732 3.646-16.047Q3.653-16.088 3.728-16.102L3.820-16.102Q3.902-16.078 3.902-16.006Q3.902-15.999 3.896-15.972Q3.783-15.575 3.412-15.336Q3.041-15.097 2.617-15.097Q2.180-15.097 1.780-15.305Q1.380-15.514 1.141-15.881Q0.901-16.248 0.901-16.700M1.571-16.970L3.386-16.970Q3.386-17.247 3.289-17.499Q3.191-17.752 2.993-17.908Q2.795-18.063 2.511-18.063Q2.234-18.063 2.021-17.905Q1.807-17.746 1.689-17.491Q1.571-17.236 1.571-16.970M6.134-13.808L4.504-13.808L4.504-14.088Q4.733-14.088 4.882-14.123Q5.030-14.157 5.030-14.297L5.030-17.643Q5.030-17.814 4.894-17.855Q4.757-17.896 4.504-17.896L4.504-18.176L5.584-18.251L5.584-17.845Q5.806-18.046 6.093-18.149Q6.380-18.251 6.688-18.251Q7.115-18.251 7.479-18.038Q7.843-17.824 8.057-17.460Q8.271-17.096 8.271-16.676Q8.271-16.231 8.031-15.867Q7.792-15.503 7.399-15.300Q7.006-15.097 6.562-15.097Q6.295-15.097 6.047-15.197Q5.799-15.298 5.611-15.479L5.611-14.297Q5.611-14.160 5.760-14.124Q5.909-14.088 6.134-14.088L6.134-13.808M5.611-17.496L5.611-15.886Q5.745-15.633 5.987-15.476Q6.230-15.319 6.507-15.319Q6.835-15.319 7.088-15.520Q7.341-15.722 7.474-16.040Q7.608-16.358 7.608-16.676Q7.608-16.905 7.543-17.134Q7.478-17.363 7.349-17.561Q7.221-17.759 7.026-17.879Q6.832-17.998 6.599-17.998Q6.305-17.998 6.037-17.869Q5.769-17.739 5.611-17.496M9.433-16.006L9.433-17.903L8.794-17.903L8.794-18.125Q9.111-18.125 9.328-18.335Q9.545-18.545 9.646-18.855Q9.747-19.164 9.747-19.472L10.014-19.472L10.014-18.183L11.090-18.183L11.090-17.903L10.014-17.903L10.014-16.019Q10.014-15.743 10.118-15.544Q10.222-15.346 10.482-15.346Q10.639-15.346 10.745-15.450Q10.851-15.555 10.901-15.708Q10.950-15.862 10.950-16.019L10.950-16.433L11.217-16.433L11.217-16.006Q11.217-15.780 11.118-15.570Q11.019-15.360 10.834-15.228Q10.649-15.097 10.420-15.097Q9.983-15.097 9.708-15.334Q9.433-15.572 9.433-16.006M13.709-15.165L12.075-15.165L12.075-15.445Q12.304-15.445 12.452-15.479Q12.601-15.514 12.601-15.654L12.601-19.273Q12.601-19.543 12.493-19.605Q12.386-19.666 12.075-19.666L12.075-19.947L13.155-20.022L13.155-17.636Q13.261-17.821 13.439-17.963Q13.616-18.104 13.825-18.178Q14.033-18.251 14.259-18.251Q14.765-18.251 15.048-18.028Q15.332-17.804 15.332-17.308L15.332-15.654Q15.332-15.517 15.481-15.481Q15.629-15.445 15.855-15.445L15.855-15.165L14.225-15.165L14.225-15.445Q14.454-15.445 14.602-15.479Q14.751-15.514 14.751-15.654L14.751-17.294Q14.751-17.629 14.631-17.829Q14.512-18.029 14.197-18.029Q13.927-18.029 13.693-17.893Q13.459-17.756 13.321-17.522Q13.182-17.288 13.182-17.014L13.182-15.654Q13.182-15.517 13.333-15.481Q13.483-15.445 13.709-15.445",[2355],[2339,6032,6033],{"transform":6020},[2344,6034],{"d":6035,"fill":2382,"stroke":2382,"className":6036,"style":5830},"M24.319-15.972L19.486-15.972Q19.418-15.982 19.372-16.028Q19.326-16.074 19.326-16.146Q19.326-16.211 19.372-16.257Q19.418-16.303 19.486-16.313L24.319-16.313Q24.388-16.303 24.434-16.257Q24.480-16.211 24.480-16.146Q24.480-16.074 24.434-16.028Q24.388-15.982 24.319-15.972M24.319-17.510L19.486-17.510Q19.418-17.520 19.372-17.566Q19.326-17.612 19.326-17.684Q19.326-17.828 19.486-17.852L24.319-17.852Q24.480-17.828 24.480-17.684Q24.480-17.612 24.434-17.566Q24.388-17.520 24.319-17.510",[2355],[2339,6038,6039],{"transform":6020},[2344,6040],{"d":6041,"fill":2382,"stroke":2382,"className":6042,"style":5830},"M29.234-15.165L27.631-15.165L27.631-15.445Q27.857-15.445 28.006-15.479Q28.154-15.514 28.154-15.654L28.154-19.273Q28.154-19.543 28.047-19.605Q27.939-19.666 27.631-19.666L27.631-19.947L28.708-20.022L28.708-15.654Q28.708-15.517 28.858-15.481Q29.009-15.445 29.234-15.445L29.234-15.165M29.829-16.676Q29.829-17.004 29.964-17.305Q30.099-17.605 30.335-17.826Q30.571-18.046 30.875-18.166Q31.179-18.286 31.504-18.286Q32.010-18.286 32.358-18.183Q32.707-18.081 32.707-17.705Q32.707-17.558 32.610-17.457Q32.512-17.356 32.365-17.356Q32.211-17.356 32.112-17.455Q32.013-17.554 32.013-17.705Q32.013-17.893 32.153-17.985Q31.952-18.036 31.511-18.036Q31.155-18.036 30.926-17.840Q30.697-17.643 30.596-17.334Q30.496-17.024 30.496-16.676Q30.496-16.327 30.622-16.021Q30.749-15.715 31.003-15.531Q31.258-15.346 31.613-15.346Q31.835-15.346 32.020-15.430Q32.205-15.514 32.340-15.669Q32.475-15.825 32.533-16.033Q32.546-16.088 32.601-16.088L32.714-16.088Q32.745-16.088 32.767-16.064Q32.789-16.040 32.789-16.006L32.789-15.985Q32.704-15.698 32.516-15.500Q32.328-15.302 32.063-15.199Q31.798-15.097 31.504-15.097Q31.073-15.097 30.685-15.303Q30.297-15.510 30.063-15.873Q29.829-16.235 29.829-16.676M33.435-15.893Q33.435-16.225 33.659-16.452Q33.883-16.679 34.226-16.807Q34.570-16.936 34.942-16.988Q35.315-17.041 35.619-17.041L35.619-17.294Q35.619-17.499 35.512-17.679Q35.404-17.858 35.223-17.961Q35.042-18.063 34.833-18.063Q34.426-18.063 34.190-17.971Q34.279-17.934 34.325-17.850Q34.372-17.766 34.372-17.664Q34.372-17.568 34.325-17.489Q34.279-17.411 34.199-17.366Q34.119-17.322 34.030-17.322Q33.879-17.322 33.779-17.419Q33.678-17.517 33.678-17.664Q33.678-18.286 34.833-18.286Q35.045-18.286 35.294-18.222Q35.544-18.159 35.746-18.040Q35.947-17.920 36.074-17.735Q36.200-17.551 36.200-17.308L36.200-15.732Q36.200-15.616 36.262-15.520Q36.323-15.425 36.436-15.425Q36.545-15.425 36.610-15.519Q36.675-15.613 36.675-15.732L36.675-16.180L36.942-16.180L36.942-15.732Q36.942-15.462 36.715-15.297Q36.487-15.131 36.207-15.131Q35.999-15.131 35.862-15.285Q35.725-15.438 35.701-15.654Q35.554-15.387 35.272-15.242Q34.990-15.097 34.666-15.097Q34.389-15.097 34.105-15.172Q33.821-15.247 33.628-15.426Q33.435-15.606 33.435-15.893M34.050-15.893Q34.050-15.719 34.151-15.589Q34.252-15.459 34.408-15.389Q34.563-15.319 34.727-15.319Q34.946-15.319 35.154-15.416Q35.363-15.514 35.491-15.695Q35.619-15.876 35.619-16.102L35.619-16.830Q35.294-16.830 34.929-16.739Q34.563-16.648 34.307-16.436Q34.050-16.225 34.050-15.893",[2355],[2339,6044,6045],{"transform":6020},[2344,6046],{"d":6047,"fill":2382,"stroke":2382,"className":6048,"style":5830},"M44.816-15.972L39.983-15.972Q39.915-15.982 39.869-16.028Q39.823-16.074 39.823-16.146Q39.823-16.211 39.869-16.257Q39.915-16.303 39.983-16.313L44.816-16.313Q44.885-16.303 44.931-16.257Q44.977-16.211 44.977-16.146Q44.977-16.074 44.931-16.028Q44.885-15.982 44.816-15.972M44.816-17.510L39.983-17.510Q39.915-17.520 39.869-17.566Q39.823-17.612 39.823-17.684Q39.823-17.828 39.983-17.852L44.816-17.852Q44.977-17.828 44.977-17.684Q44.977-17.612 44.931-17.566Q44.885-17.520 44.816-17.510",[2355],[2339,6050,6051],{"transform":6020},[2344,6052],{"d":6053,"fill":2382,"stroke":2382,"className":6054,"style":5830},"M49.239-15.097Q48.915-15.097 48.670-15.254Q48.426-15.411 48.294-15.676Q48.163-15.941 48.163-16.266Q48.163-16.734 48.416-17.197Q48.668-17.660 49.092-17.956Q49.516-18.251 49.988-18.251Q50.203-18.251 50.389-18.147Q50.576-18.043 50.695-17.858Q50.719-17.971 50.813-18.045Q50.907-18.118 51.023-18.118Q51.126-18.118 51.194-18.057Q51.263-17.995 51.263-17.896Q51.263-17.838 51.256-17.811L50.774-15.893Q50.747-15.736 50.747-15.647Q50.747-15.520 50.798-15.420Q50.849-15.319 50.969-15.319Q51.191-15.319 51.304-15.572Q51.416-15.825 51.502-16.194Q51.526-16.255 51.577-16.255L51.690-16.255Q51.724-16.255 51.746-16.226Q51.769-16.197 51.769-16.173Q51.769-16.160 51.762-16.146Q51.499-15.097 50.955-15.097Q50.706-15.097 50.497-15.220Q50.289-15.343 50.220-15.572Q49.745-15.097 49.239-15.097M49.253-15.319Q49.526-15.319 49.778-15.503Q50.029-15.688 50.220-15.955L50.589-17.435Q50.552-17.595 50.471-17.732Q50.391-17.869 50.265-17.949Q50.138-18.029 49.974-18.029Q49.766-18.029 49.579-17.905Q49.393-17.780 49.255-17.588Q49.116-17.397 49.031-17.195Q48.918-16.901 48.834-16.556Q48.750-16.211 48.750-15.961Q48.750-15.705 48.879-15.512Q49.007-15.319 49.253-15.319",[2355],[2481,6056,6058,6059,414,6074,6089,6090,437],{"className":6057},[2484],"Euler tour reduces LCA to range-minimum: between ",[390,6060,6062],{"className":6061},[393],[390,6063,6065],{"className":6064,"ariaHidden":398},[397],[390,6066,6068,6071],{"className":6067},[402],[390,6069],{"className":6070,"style":407},[406],[390,6072,413],{"className":6073},[411,412],[390,6075,6077],{"className":6076},[393],[390,6078,6080],{"className":6079,"ariaHidden":398},[397],[390,6081,6083,6086],{"className":6082},[402],[390,6084],{"className":6085,"style":407},[406],[390,6087,431],{"className":6088,"style":430},[411,412]," in the tour, the shallowest (minimum-depth) entry is ",[390,6091,6093],{"className":6092},[393],[390,6094,6096,6135],{"className":6095,"ariaHidden":398},[397],[390,6097,6099,6102,6108,6111,6114,6117,6120,6123,6126,6129,6132],{"className":6098},[402],[390,6100],{"className":6101,"style":586},[406],[390,6103,6105],{"className":6104},[590],[390,6106,595],{"className":6107},[411,594],[390,6109,600],{"className":6110},[599],[390,6112,413],{"className":6113},[411,412],[390,6115,608],{"className":6116},[607],[390,6118],{"className":6119,"style":613},[612],[390,6121,431],{"className":6122,"style":430},[411,412],[390,6124,621],{"className":6125},[620],[390,6127],{"className":6128,"style":845},[612],[390,6130,850],{"className":6131},[849],[390,6133],{"className":6134,"style":845},[612],[390,6136,6138,6141],{"className":6137},[402],[390,6139],{"className":6140,"style":407},[406],[390,6142,500],{"className":6143},[411,412],[5529,6145,6146],{},[5532,6147,6148,6151,6152,6155,6156,6210,6211],{},[434,6149,6150],{},"Tarjan's offline LCA."," If all query pairs are known in advance, a single ",[500,6153,6154],{"href":158},"DFS","\nwith a union-find structure answers them in near-linear ",[390,6157,6159],{"className":6158},[393],[390,6160,6162,6187],{"className":6161,"ariaHidden":398},[397],[390,6163,6165,6168,6171,6175,6178,6181,6184],{"className":6164},[402],[390,6166],{"className":6167,"style":586},[406],[390,6169,798],{"className":6170,"style":463},[411,412],[390,6172,6174],{"className":6173},[599],"((",[390,6176,880],{"className":6177},[411,412],[390,6179],{"className":6180,"style":1546},[612],[390,6182,1842],{"className":6183},[1397],[390,6185],{"className":6186,"style":1546},[612],[390,6188,6190,6193,6196,6199,6202,6207],{"className":6189},[402],[390,6191],{"className":6192,"style":586},[406],[390,6194,944],{"className":6195,"style":430},[411,412],[390,6197,621],{"className":6198},[620],[390,6200],{"className":6201,"style":613},[612],[390,6203,6206],{"className":6204,"style":6205},[411,412],"margin-right:0.0037em;","α",[390,6208,621],{"className":6209},[620]," total\ntime, processing each query when its second endpoint is first reached.",[5520,6212,6213],{},[500,6214,4951],{"href":6215,"ariaDescribedBy":6216,"dataFootnoteRef":376,"id":6217},"#user-content-fn-tarjan",[5526],"user-content-fnref-tarjan",[439,6219,6220],{"type":3526},[381,6221,6222,6225,6226,6229,6230,6263,6264,6267,6268,6283,6284,6323,6324,6348],{},[434,6223,6224],{},"Remark (How to choose)."," Binary lifting is ",[434,6227,6228],{},"online"," (queries may arrive one at a\ntime), needs only parent pointers and a DFS, answers in ",[390,6231,6233],{"className":6232},[393],[390,6234,6236],{"className":6235,"ariaHidden":398},[397],[390,6237,6239,6242,6245,6248,6254,6257,6260],{"className":6238},[402],[390,6240],{"className":6241,"style":586},[406],[390,6243,798],{"className":6244,"style":463},[411,412],[390,6246,600],{"className":6247},[599],[390,6249,6251],{"className":6250},[590],[390,6252,873],{"className":6253,"style":872},[411,594],[390,6255],{"className":6256,"style":613},[612],[390,6258,880],{"className":6259},[411,412],[390,6261,621],{"className":6262},[620],", and is the\n",[385,6265,6266],{},"only"," one of the three that also serves ",[390,6269,6271],{"className":6270},[393],[390,6272,6274],{"className":6273,"ariaHidden":398},[397],[390,6275,6277,6280],{"className":6276},[402],[390,6278],{"className":6279,"style":822},[406],[390,6281,1021],{"className":6282,"style":1020},[411,412],"-th-ancestor queries — at the cost\nof ",[390,6285,6287],{"className":6286},[393],[390,6288,6290],{"className":6289,"ariaHidden":398},[397],[390,6291,6293,6296,6299,6302,6305,6308,6314,6317,6320],{"className":6292},[402],[390,6294],{"className":6295,"style":586},[406],[390,6297,798],{"className":6298,"style":463},[411,412],[390,6300,600],{"className":6301},[599],[390,6303,880],{"className":6304},[411,412],[390,6306],{"className":6307,"style":613},[612],[390,6309,6311],{"className":6310},[590],[390,6312,873],{"className":6313,"style":872},[411,594],[390,6315],{"className":6316,"style":613},[612],[390,6318,880],{"className":6319},[411,412],[390,6321,621],{"className":6322},[620]," space. Reach for Euler+RMQ when you need ",[390,6325,6327],{"className":6326},[393],[390,6328,6330],{"className":6329,"ariaHidden":398},[397],[390,6331,6333,6336,6339,6342,6345],{"className":6332},[402],[390,6334],{"className":6335,"style":586},[406],[390,6337,798],{"className":6338,"style":463},[411,412],[390,6340,600],{"className":6341},[599],[390,6343,1402],{"className":6344},[411],[390,6346,621],{"className":6347},[620]," LCA on a fixed\ntree, and Tarjan when every query is known up front and you want the lowest\ntotal cost.",[694,6350,6352],{"id":6351},"takeaways","Takeaways",[5529,6354,6355,6391,6447,6710,6801,6971],{},[5532,6356,4525,6357,6359,6360,414,6375,6390],{},[434,6358,572],{}," of ",[390,6361,6363],{"className":6362},[393],[390,6364,6366],{"className":6365,"ariaHidden":398},[397],[390,6367,6369,6372],{"className":6368},[402],[390,6370],{"className":6371,"style":407},[406],[390,6373,413],{"className":6374},[411,412],[390,6376,6378],{"className":6377},[393],[390,6379,6381],{"className":6380,"ariaHidden":398},[397],[390,6382,6384,6387],{"className":6383},[402],[390,6385],{"className":6386,"style":407},[406],[390,6388,431],{"className":6389,"style":430},[411,412]," is the deepest node ancestral to\nboth; it is unique because ancestor sets are root-chains.",[5532,6392,4525,6393,6396,6397,6421,6422,6446],{},[434,6394,6395],{},"naive walk"," (equalize depth, climb together) needs no preprocessing but\ncosts ",[390,6398,6400],{"className":6399},[393],[390,6401,6403],{"className":6402,"ariaHidden":398},[397],[390,6404,6406,6409,6412,6415,6418],{"className":6405},[402],[390,6407],{"className":6408,"style":586},[406],[390,6410,798],{"className":6411,"style":463},[411,412],[390,6413,600],{"className":6414},[599],[390,6416,805],{"className":6417},[411,412],[390,6419,621],{"className":6420},[620]," per query, or ",[390,6423,6425],{"className":6424},[393],[390,6426,6428],{"className":6427,"ariaHidden":398},[397],[390,6429,6431,6434,6437,6440,6443],{"className":6430},[402],[390,6432],{"className":6433,"style":586},[406],[390,6435,918],{"className":6436},[411],[390,6438,600],{"className":6439},[599],[390,6441,880],{"className":6442},[411,412],[390,6444,621],{"className":6445},[620]," on a degenerate tree.",[5532,6448,6449,6451,6452,6488,6489,6530,6531,6669,6670,6709],{},[434,6450,981],{}," precomputes ",[390,6453,6455],{"className":6454},[393],[390,6456,6458],{"className":6457,"ariaHidden":398},[397],[390,6459,6461,6464,6467,6470,6473,6476,6479,6482,6485],{"className":6460},[402],[390,6462],{"className":6463,"style":586},[406],[390,6465,413],{"className":6466},[411,412],[390,6468,381],{"className":6469},[411,412],[390,6471,1106],{"className":6472},[599],[390,6474,431],{"className":6475,"style":430},[411,412],[390,6477,1113],{"className":6478},[620],[390,6480,1106],{"className":6481},[599],[390,6483,1021],{"className":6484,"style":1020},[411,412],[390,6486,1113],{"className":6487},[620],", the ",[390,6490,6492],{"className":6491},[393],[390,6493,6495],{"className":6494,"ariaHidden":398},[397],[390,6496,6498,6501],{"className":6497},[402],[390,6499],{"className":6500,"style":1035},[406],[390,6502,6504,6507],{"className":6503},[411],[390,6505,1042],{"className":6506},[411],[390,6508,6510],{"className":6509},[1046],[390,6511,6513],{"className":6512},[1050],[390,6514,6516],{"className":6515},[1054],[390,6517,6519],{"className":6518,"style":1035},[1058],[390,6520,6521,6524],{"style":1061},[390,6522],{"className":6523,"style":1066},[1065],[390,6525,6527],{"className":6526},[1070,1071,1072,1073],[390,6528,1021],{"className":6529,"style":1020},[411,412,1073],"-th ancestor, via the\ndoubling identity ",[390,6532,6534],{"className":6533},[393],[390,6535,6537,6576,6624,6657],{"className":6536,"ariaHidden":398},[397],[390,6538,6540,6543,6546,6549,6552,6555,6558,6561,6564,6567,6570,6573],{"className":6539},[402],[390,6541],{"className":6542,"style":586},[406],[390,6544,413],{"className":6545},[411,412],[390,6547,381],{"className":6548},[411,412],[390,6550,1106],{"className":6551},[599],[390,6553,431],{"className":6554,"style":430},[411,412],[390,6556,1113],{"className":6557},[620],[390,6559,1106],{"className":6560},[599],[390,6562,1021],{"className":6563,"style":1020},[411,412],[390,6565,1113],{"className":6566},[620],[390,6568],{"className":6569,"style":845},[612],[390,6571,850],{"className":6572},[849],[390,6574],{"className":6575,"style":845},[612],[390,6577,6579,6582,6585,6588,6591,6594,6597,6600,6603,6606,6609,6612,6615,6618,6621],{"className":6578},[402],[390,6580],{"className":6581,"style":586},[406],[390,6583,413],{"className":6584},[411,412],[390,6586,381],{"className":6587},[411,412],[390,6589,1106],{"className":6590},[599],[390,6592],{"className":6593,"style":613},[612],[390,6595,413],{"className":6596},[411,412],[390,6598,381],{"className":6599},[411,412],[390,6601,1106],{"className":6602},[599],[390,6604,431],{"className":6605,"style":430},[411,412],[390,6607,1113],{"className":6608},[620],[390,6610,1106],{"className":6611},[599],[390,6613,1021],{"className":6614,"style":1020},[411,412],[390,6616],{"className":6617,"style":1546},[612],[390,6619,1398],{"className":6620},[1397],[390,6622],{"className":6623,"style":1546},[612],[390,6625,6627,6630,6633,6636,6639,6642,6645,6648,6651,6654],{"className":6626},[402],[390,6628],{"className":6629,"style":586},[406],[390,6631,1402],{"className":6632},[411],[390,6634,1113],{"className":6635},[620],[390,6637],{"className":6638,"style":613},[612],[390,6640,1113],{"className":6641},[620],[390,6643,1106],{"className":6644},[599],[390,6646,1021],{"className":6647,"style":1020},[411,412],[390,6649],{"className":6650,"style":1546},[612],[390,6652,1398],{"className":6653},[1397],[390,6655],{"className":6656,"style":1546},[612],[390,6658,6660,6663,6666],{"className":6659},[402],[390,6661],{"className":6662,"style":586},[406],[390,6664,1402],{"className":6665},[411],[390,6667,1113],{"className":6668},[620]," in ",[390,6671,6673],{"className":6672},[393],[390,6674,6676],{"className":6675,"ariaHidden":398},[397],[390,6677,6679,6682,6685,6688,6691,6694,6700,6703,6706],{"className":6678},[402],[390,6680],{"className":6681,"style":586},[406],[390,6683,798],{"className":6684,"style":463},[411,412],[390,6686,600],{"className":6687},[599],[390,6689,880],{"className":6690},[411,412],[390,6692],{"className":6693,"style":613},[612],[390,6695,6697],{"className":6696},[590],[390,6698,873],{"className":6699,"style":872},[411,594],[390,6701],{"className":6702,"style":613},[612],[390,6704,880],{"className":6705},[411,412],[390,6707,621],{"className":6708},[620]," time and\nspace.",[5532,6711,6712,6713,6731,6732,6747,6748,6763,6764,6767,6768,437],{},"A ",[434,6714,6715,6730],{},[390,6716,6718],{"className":6717},[393],[390,6719,6721],{"className":6720,"ariaHidden":398},[397],[390,6722,6724,6727],{"className":6723},[402],[390,6725],{"className":6726,"style":822},[406],[390,6728,1021],{"className":6729,"style":1020},[411,412],"-th-ancestor"," query jumps by each ",[390,6733,6735],{"className":6734},[393],[390,6736,6738],{"className":6737,"ariaHidden":398},[397],[390,6739,6741,6744],{"className":6740},[402],[390,6742],{"className":6743,"style":1448},[406],[390,6745,1402],{"className":6746},[411],"-bit of ",[390,6749,6751],{"className":6750},[393],[390,6752,6754],{"className":6753,"ariaHidden":398},[397],[390,6755,6757,6760],{"className":6756},[402],[390,6758],{"className":6759,"style":822},[406],[390,6761,1021],{"className":6762,"style":1020},[411,412],"; an ",[434,6765,6766],{},"LCA"," query\nlifts the deeper node to equal depth, then jumps both up by decreasing powers of\ntwo while they stay distinct — each ",[390,6769,6771],{"className":6770},[393],[390,6772,6774],{"className":6773,"ariaHidden":398},[397],[390,6775,6777,6780,6783,6786,6792,6795,6798],{"className":6776},[402],[390,6778],{"className":6779,"style":586},[406],[390,6781,798],{"className":6782,"style":463},[411,412],[390,6784,600],{"className":6785},[599],[390,6787,6789],{"className":6788},[590],[390,6790,873],{"className":6791,"style":872},[411,594],[390,6793],{"className":6794,"style":613},[612],[390,6796,880],{"className":6797},[411,412],[390,6799,621],{"className":6800},[620],[5532,6802,6803,1666,6806,6936,6937,6970],{},[434,6804,6805],{},"Tree distance",[390,6807,6809],{"className":6808},[393],[390,6810,6812,6848,6884],{"className":6811,"ariaHidden":398},[397],[390,6813,6815,6818,6821,6824,6827,6830,6833,6836,6839,6842,6845],{"className":6814},[402],[390,6816],{"className":6817,"style":586},[406],[390,6819,3257],{"className":6820},[411,412],[390,6822,1288],{"className":6823},[411,412],[390,6825,3264],{"className":6826},[411,412],[390,6828,805],{"className":6829},[411,412],[390,6831,1106],{"className":6832},[599],[390,6834,413],{"className":6835},[411,412],[390,6837,1113],{"className":6838},[620],[390,6840],{"className":6841,"style":1546},[612],[390,6843,1842],{"className":6844},[1397],[390,6846],{"className":6847,"style":1546},[612],[390,6849,6851,6854,6857,6860,6863,6866,6869,6872,6875,6878,6881],{"className":6850},[402],[390,6852],{"className":6853,"style":586},[406],[390,6855,3257],{"className":6856},[411,412],[390,6858,1288],{"className":6859},[411,412],[390,6861,3264],{"className":6862},[411,412],[390,6864,805],{"className":6865},[411,412],[390,6867,1106],{"className":6868},[599],[390,6870,431],{"className":6871,"style":430},[411,412],[390,6873,1113],{"className":6874},[620],[390,6876],{"className":6877,"style":1546},[612],[390,6879,1398],{"className":6880},[1397],[390,6882],{"className":6883,"style":1546},[612],[390,6885,6887,6890,6893,6896,6899,6902,6905,6908,6911,6917,6920,6923,6926,6929,6932],{"className":6886},[402],[390,6888],{"className":6889,"style":586},[406],[390,6891,1042],{"className":6892},[411],[390,6894],{"className":6895,"style":613},[612],[390,6897,3257],{"className":6898},[411,412],[390,6900,1288],{"className":6901},[411,412],[390,6903,3264],{"className":6904},[411,412],[390,6906,805],{"className":6907},[411,412],[390,6909,1106],{"className":6910},[599],[390,6912,6914],{"className":6913},[590],[390,6915,595],{"className":6916},[411,594],[390,6918,600],{"className":6919},[599],[390,6921,413],{"className":6922},[411,412],[390,6924,608],{"className":6925},[607],[390,6927],{"className":6928,"style":613},[612],[390,6930,431],{"className":6931,"style":430},[411,412],[390,6933,6935],{"className":6934},[620],")]",",\nturning path queries into ",[390,6938,6940],{"className":6939},[393],[390,6941,6943],{"className":6942,"ariaHidden":398},[397],[390,6944,6946,6949,6952,6955,6961,6964,6967],{"className":6945},[402],[390,6947],{"className":6948,"style":586},[406],[390,6950,798],{"className":6951,"style":463},[411,412],[390,6953,600],{"className":6954},[599],[390,6956,6958],{"className":6957},[590],[390,6959,873],{"className":6960,"style":872},[411,594],[390,6962],{"className":6963,"style":613},[612],[390,6965,880],{"className":6966},[411,412],[390,6968,621],{"className":6969},[620]," arithmetic.",[5532,6972,6973,6974,6977,6978,7002,7003,7006,7007,7022],{},"Alternatives: ",[434,6975,6976],{},"Euler tour + sparse-table RMQ"," gives ",[390,6979,6981],{"className":6980},[393],[390,6982,6984],{"className":6983,"ariaHidden":398},[397],[390,6985,6987,6990,6993,6996,6999],{"className":6986},[402],[390,6988],{"className":6989,"style":586},[406],[390,6991,798],{"className":6992,"style":463},[411,412],[390,6994,600],{"className":6995},[599],[390,6997,1402],{"className":6998},[411],[390,7000,621],{"className":7001},[620]," queries on a static\ntree; ",[434,7004,7005],{},"Tarjan's"," union-find DFS answers all queries offline in near-linear\ntime. Binary lifting wins on being online and also serving ",[390,7008,7010],{"className":7009},[393],[390,7011,7013],{"className":7012,"ariaHidden":398},[397],[390,7014,7016,7019],{"className":7015},[402],[390,7017],{"className":7018,"style":822},[406],[390,7020,1021],{"className":7021,"style":1020},[411,412],"-th ancestors.",[7024,7025,7028,7033],"section",{"className":7026,"dataFootnotes":376},[7027],"footnotes",[694,7029,7032],{"className":7030,"id":5526},[7031],"sr-only","Footnotes",[7034,7035,7036,7050,7127],"ol",{},[5532,7037,7039,7042,7043],{"id":7038},"user-content-fn-cprefs",[434,7040,7041],{},"Skiena",", § — Trees \u002F LCA: survey of LCA strategies and the preprocessing\u002Fquery trade-off across query models. ",[500,7044,7049],{"href":7045,"ariaLabel":7046,"className":7047,"dataFootnoteBackref":376},"#user-content-fnref-cprefs","Back to reference 1",[7048],"data-footnote-backref","↩",[5532,7051,7053,7056,7057,7081,7082,7121,7122],{"id":7052},"user-content-fn-euler",[434,7054,7055],{},"Erickson",", Ch. — Trees: the Euler-tour reduction of LCA to range-minimum, with sparse-table RMQ giving ",[390,7058,7060],{"className":7059},[393],[390,7061,7063],{"className":7062,"ariaHidden":398},[397],[390,7064,7066,7069,7072,7075,7078],{"className":7065},[402],[390,7067],{"className":7068,"style":586},[406],[390,7070,798],{"className":7071,"style":463},[411,412],[390,7073,600],{"className":7074},[599],[390,7076,1402],{"className":7077},[411],[390,7079,621],{"className":7080},[620]," queries after ",[390,7083,7085],{"className":7084},[393],[390,7086,7088],{"className":7087,"ariaHidden":398},[397],[390,7089,7091,7094,7097,7100,7103,7106,7112,7115,7118],{"className":7090},[402],[390,7092],{"className":7093,"style":586},[406],[390,7095,798],{"className":7096,"style":463},[411,412],[390,7098,600],{"className":7099},[599],[390,7101,880],{"className":7102},[411,412],[390,7104],{"className":7105,"style":613},[612],[390,7107,7109],{"className":7108},[590],[390,7110,873],{"className":7111,"style":872},[411,594],[390,7113],{"className":7114,"style":613},[612],[390,7116,880],{"className":7117},[411,412],[390,7119,621],{"className":7120},[620]," preprocessing. ",[500,7123,7049],{"href":7124,"ariaLabel":7125,"className":7126,"dataFootnoteBackref":376},"#user-content-fnref-euler","Back to reference 2",[7048],[5532,7128,7130,7133,7134,7173,7174],{"id":7129},"user-content-fn-tarjan",[434,7131,7132],{},"CLRS",", Ch. — (trees): Tarjan's offline LCA via depth-first search and disjoint-set union, near-linear in ",[390,7135,7137],{"className":7136},[393],[390,7138,7140,7161],{"className":7139,"ariaHidden":398},[397],[390,7141,7143,7146,7149,7152,7155,7158],{"className":7142},[402],[390,7144],{"className":7145,"style":586},[406],[390,7147,600],{"className":7148},[599],[390,7150,880],{"className":7151},[411,412],[390,7153],{"className":7154,"style":1546},[612],[390,7156,1842],{"className":7157},[1397],[390,7159],{"className":7160,"style":1546},[612],[390,7162,7164,7167,7170],{"className":7163},[402],[390,7165],{"className":7166,"style":586},[406],[390,7168,944],{"className":7169,"style":430},[411,412],[390,7171,621],{"className":7172},[620],". ",[500,7175,7049],{"href":7176,"ariaLabel":7177,"className":7178,"dataFootnoteBackref":376},"#user-content-fnref-tarjan","Back to reference 3",[7048],[7180,7181,7182],"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":7184},[7185,7186,7192,7193,7194,7195,7196],{"id":696,"depth":18,"text":697},{"id":980,"depth":18,"text":981,"children":7187},[7188,7190],{"id":2597,"depth":24,"text":7189},"k-th ancestor in O(logn)",{"id":3200,"depth":24,"text":7191},"LCA in O(logn)",{"id":4201,"depth":18,"text":4202},{"id":4977,"depth":18,"text":4978},{"id":5514,"depth":18,"text":5515},{"id":6351,"depth":18,"text":6352},{"id":5526,"depth":18,"text":7032},"The previous lessons gave us a rooted tree and a single root-to-node path for\neach vertex. Many problems instead ask about two vertices at once: how far\napart are u and v? what is the highest fork their paths share? which company\ncontains both of two nested regions? Each reduces to one question: the lowest\ncommon ancestor.","md",{"moduleNumber":108,"lessonNumber":116,"order":7200},607,true,[7203,7207,7211,7214],{"title":7204,"slug":7205,"difficulty":7206},"Lowest Common Ancestor of a Binary Tree","lowest-common-ancestor-of-a-binary-tree","Medium",{"title":7208,"slug":7209,"difficulty":7210},"Kth Ancestor of a Tree Node","kth-ancestor-of-a-tree-node","Hard",{"title":7212,"slug":7213,"difficulty":7206},"Step-By-Step Directions From a Binary Tree Node to Another","step-by-step-directions-from-a-binary-tree-node-to-another",{"title":7215,"slug":7216,"difficulty":7206},"Smallest Common Region","smallest-common-region","---\ntitle: Lowest Common Ancestor & Binary Lifting\nmodule: Graphs\nmoduleNumber: 6\nlessonNumber: 7\norder: 607\nsummary: >-\n  Given a rooted tree, the lowest common ancestor of $u$ and $v$ is the deepest\n  node that is an ancestor of both. A naive walk answers one query in $O(h)$;\n  **binary lifting** precomputes the $2^k$-th ancestor of every node in\n  $O(n\\log n)$, then answers $k$-th-ancestor and LCA queries in $O(\\log n)$ each.\n  We derive both jumps, apply them to tree distance, and compare against the\n  Euler-tour + RMQ and Tarjan offline alternatives.\ntopics: [Graphs]\nsources:\n  - book: CLRS\n    ref: \"Ch. — (trees)\"\n  - book: Skiena\n    ref: \"§ — Trees \u002F LCA\"\n  - book: Erickson\n    ref: \"Ch. — Trees\"\npractice:\n  - title: 'Lowest Common Ancestor of a Binary Tree'\n    slug: lowest-common-ancestor-of-a-binary-tree\n    difficulty: Medium\n  - title: 'Kth Ancestor of a Tree Node'\n    slug: kth-ancestor-of-a-tree-node\n    difficulty: Hard\n  - title: 'Step-By-Step Directions From a Binary Tree Node to Another'\n    slug: step-by-step-directions-from-a-binary-tree-node-to-another\n    difficulty: Medium\n  - title: 'Smallest Common Region'\n    slug: smallest-common-region\n    difficulty: Medium\n---\n\nThe previous lessons gave us a rooted tree and a single root-to-node path for\neach vertex. Many problems instead ask about _two_ vertices at once: how far\napart are $u$ and $v$? what is the highest fork their paths share? which company\ncontains both of two nested regions? Each reduces to one question: the **lowest\ncommon ancestor**.\n\n> **Definition.** Fix a root $r$ of a tree $T$. A node $a$ is an **ancestor** of\n> $v$ if $a$ lies on the path from $r$ to $v$ (every node is its own ancestor).\n> The **lowest common ancestor** $\\operatorname{lca}(u,v)$ is the ancestor of\n> both $u$ and $v$ that is **deepest** — farthest from the root.\n\nThe LCA is well defined and unique: the sets of ancestors of $u$ and of $v$ are\neach a chain from the root, so their intersection is a chain, and a finite chain\nhas a unique deepest element.\n\n## The naive walk\n\nIf every node stores a parent pointer and a depth, one query is easy. Lift the\ndeeper of $u,v$ until both sit at the same depth, then advance both pointers up\nin lockstep; the first node they agree on is the LCA.\n\n```algorithm\ncaption: $\\textsc{Naive-LCA}(u, v)$ — climb to equal depth, then together\nwhile $depth[u] > depth[v]$ do\n  $u \\gets parent[u]$\nwhile $depth[v] > depth[u]$ do\n  $v \\gets parent[v]$\nwhile $u \\ne v$ do\n  $u \\gets parent[u]$\n  $v \\gets parent[v]$\nreturn $u$\n```\n\nThis needs no preprocessing and is correct, but each step moves up one edge, so a\nquery costs $O(h)$ where $h$ is the tree's height. On a balanced tree $h =\nO(\\log n)$, but on a degenerate path $h = \\Theta(n)$, and $q$ queries cost\n$O(qn)$. We want a query cost that does not depend on shape. (For the asymptotic\nnotation, see [asymptotic analysis](\u002Falgorithms\u002Ffoundations\u002Fasymptotic-analysis).)\n\n## Binary lifting\n\nThe fix is to make each jump cover an exponentially larger distance. Instead of\n\"go up one,\" precompute, for every node $v$ and every $k$, a pointer that goes up\n$2^k$ edges at once.\n\n> **Definition.** Let $up[v][k]$ be the $2^k$-th ancestor of $v$, the node\n> reached by following parent pointers $2^k$ times (or the root, if that would\n> climb past it). In particular $up[v][0] = parent[v]$.\n\nThe whole table is built from a single doubling identity: climbing $2^k$ edges is\nclimbing $2^{k-1}$ edges _twice_.\n\n> **Lemma (doubling).** For $k \\ge 1$,\n> $$up[v][k] = up\\bigl[\\,up[v][k-1]\\,\\bigr][k-1].$$\n>\n\n> **Proof.** $up[v][k-1]$ is $2^{k-1}$ edges above $v$; applying the same jump to it\n> climbs another $2^{k-1}$ edges, for $2^{k-1} + 2^{k-1} = 2^k$ total. $\\qed$\n\nSo column $k$ of the table is computed entirely from column $k-1$, one pass per\npower of two. The number of columns is $K = \\lceil \\log_2 n \\rceil$, since no node\nhas an ancestor more than $n-1$ edges up.\n\n```algorithm\ncaption: $\\textsc{Build-Up}(T)$ — preprocess $2^k$-th ancestors via doubling\nrun a DFS\u002FBFS from the root to fill $parent[\\cdot]$ and $depth[\\cdot]$\nfor each node $v$ do\n  $up[v][0] \\gets parent[v]$  \u002F\u002F root points to itself\nfor $k \\gets 1$ to $K$ do\n  for each node $v$ do\n    $up[v][k] \\gets up[\\,up[v][k-1]\\,][k-1]$\n```\n\nThe table has $n(K{+}1)$ entries and each costs $O(1)$, so preprocessing is\n$O(n\\log n)$ time and $O(n\\log n)$ space.\n\n$$\n% caption: doubling identity: $up[v][2]$ (a $4$-edge climb) is two $up[\\cdot][1]$ jumps of\n%          $2$ edges each\n\\begin{tikzpicture}[\n  every node\u002F.style={circle, draw, minimum size=7mm, inner sep=0pt, font=\\small},\n  >=stealth]\n  \\definecolor{acc}{HTML}{2348F2}\n  \\node (v)  at (0,0)    {$v$};\n  \\node (n1) at (0,-1.0) {};\n  \\node (m)  at (0,-2.0) {$m$};\n  \\node (n3) at (0,-3.0) {};\n  \\node (w)  at (0,-4.0) {$w$};\n  \\draw (v)--(n1)--(m)--(n3)--(w);\n  \\draw[->, acc, thick, bend left=60] (v) to node[draw=none, right=1mm, font=\\footnotesize, text=acc]{$2^1$} (m);\n  \\draw[->, acc, thick, bend left=60] (m) to node[draw=none, right=1mm, font=\\footnotesize, text=acc]{$2^1$} (w);\n  \\draw[->, thick, bend right=55] (v) to node[draw=none, left=1mm, font=\\footnotesize]{$2^2=up[v][2]$} (w);\n\\end{tikzpicture}\n$$\n\n### $k$-th ancestor in $O(\\log n)$\n\nAny non-negative integer $k$ has a unique binary expansion, so the climb of $k$\nedges decomposes into jumps of size $2^0, 2^1, 2^2, \\dots$, one jump per set bit.\nTake each set bit from low to high and follow the matching column of `up`.\n\n```algorithm\ncaption: $\\textsc{Kth-Ancestor}(v, k)$ — jump by each 1-bit of $k$\nfor $j \\gets 0$ to $K$ do\n  if $k$ has bit $j$ set then\n    $v \\gets up[v][j]$\n    if $v = \\text{nil}$ then return nil  \u002F\u002F ran off the root\nreturn $v$\n```\n\nAt most $K+1$ bits are set, so this is $O(\\log n)$. The order of the jumps does\nnot matter for the _destination_ (they compose to the same total climb), but\nprocessing low bits first keeps the running node well-defined at each step.\n\n$$\n% caption: $5=101_2$ splits the $5$-edge climb into a $2^0$ jump then a $2^2$ jump (one\n%          per set bit)\n\\begin{tikzpicture}[\n  every node\u002F.style={circle, draw, minimum size=7mm, inner sep=0pt, font=\\small},\n  >=stealth]\n  \\definecolor{acc}{HTML}{2348F2}\n  \\node (v)  at (0,0)    {$v$};\n  \\node (a1) at (0,-0.95){};\n  \\node (a2) at (0,-1.9) {};\n  \\node (a3) at (0,-2.85){};\n  \\node (a4) at (0,-3.8) {};\n  \\node (a5) at (0,-4.75){};\n  \\draw (v)--(a1)--(a2)--(a3)--(a4)--(a5);\n  \\draw[->, acc, thick, bend left=70] (v)  to node[draw=none, right=1mm, font=\\footnotesize, text=acc]{$2^0$} (a1);\n  \\draw[->, acc, thick, bend right=45] (a1) to node[draw=none, left=1mm, font=\\footnotesize, text=acc]{$2^2$} (a5);\n  \\node[draw=none, font=\\footnotesize] at (2.0,-2.85) {$5 = 101_2$};\n\\end{tikzpicture}\n$$\n\n### LCA in $O(\\log n)$\n\nThe LCA query reuses the same jumps as two phases. **Phase 1** lifts the deeper\nnode up by exactly $depth[u] - depth[v]$, a single $\\textsc{Kth-Ancestor}$ call,\nso $u$ and $v$ sit at equal depth. If they now coincide, one was an ancestor of\nthe other and we are done. **Phase 2** lifts _both_ nodes simultaneously: scanning\n$k$ from high to low, we jump both up by $2^k$ **only when that keeps them\ndistinct**. When the loop ends, $u$ and $v$ are the two distinct children-side\nnodes just _below_ the LCA, so the answer is their common parent.\n\n```algorithm\ncaption: $\\textsc{LCA}(u, v)$ — equalize depth, then jump both up greedily\nif $depth[u] \u003C depth[v]$ then swap $u, v$\n$u \\gets \\textsc{Kth-Ancestor}(u,\\ depth[u] - depth[v])$  \u002F\u002F phase 1\nif $u = v$ then return $u$\nfor $k \\gets K$ downto $0$ do                              \u002F\u002F phase 2\n  if $up[u][k] \\ne up[v][k]$ then\n    $u \\gets up[u][k]$\n    $v \\gets up[v][k]$\nreturn $up[u][0]$  \u002F\u002F their common parent\n```\n\n> **Remark (Why high-to-low greedy is correct).** Let $d$ be the number of edges from the\n> equalized $u$ up to the LCA (the same for $v$). We must climb $u$ and $v$ up by\n> exactly $d-1$, stopping one short so they land on the LCA's two distinct\n> descendants, and then take one parent step. Scanning $k$ from high to low and\n> jumping whenever the targets _differ_ is precisely the greedy construction of\n> $d-1$ in binary: a jump of $2^k$ is taken iff it does not overshoot the LCA\n> (overshooting would make $up[u][k]$ and $up[v][k]$ equal). It is the same\n> high-to-low bit selection used throughout binary lifting.\n\nThe depth-equalizing jump is $O(\\log n)$ and the second loop runs $K+1$ times, so\neach LCA query is $O(\\log n)$ after the one-time $O(n\\log n)$ build.\n\n$$\n% caption: Lift the deeper node to equal depth, then jump both up by decreasing powers of\n%          two; the LCA is highlighted\n\\begin{tikzpicture}[\n  every node\u002F.style={circle, draw, minimum size=7mm, inner sep=0, font=\\small},\n  level distance=11mm, sibling distance=15mm, >=stealth]\n  \\definecolor{acc}{HTML}{2348F2}\n  \\node (r) {$r$}\n    child {node (a) {$a$}\n      child {node (l) {$c$}\n        child {node (u) {$u$}}\n        child[missing]\n      }\n      child {node (b) {$b$}\n        child {node (v) {$v$}}\n        child[missing]\n      }\n    }\n    child[missing];\n  \\node[draw=acc, very thick, minimum size=7mm, inner sep=0] at (a) {};\n  \\draw[->, acc, thick, dashed, bend left=20] (u) to (l);\n  \\draw[->, acc, thick, dashed, bend left=25] (l) to (a);\n  \\draw[->, acc, thick, dashed, bend right=25] (v) to (b);\n  \\draw[->, acc, thick, dashed, bend right=25] (b) to (a);\n\\end{tikzpicture}\n$$\n\nHere $u$ and $v$ already share depth; both lift to $c$ and $b$ (kept distinct),\nthen one parent step lands on $a = \\operatorname{lca}(u,v)$, drawn in `acc`.\n\n## A worked table\n\nThe whole method lives in the `up` grid. For the small tree below, rows are nodes\nand columns are $k = 0,1,2$, with each entry the $2^k$-th ancestor. Column $0$ is\nthe parent; every later column is the previous column composed with itself.\n\n$$\n% caption: The $up[v][k]$ table — $2^k$-th ancestors, each column doubled from the last;\n%          one query's jump cells in acc\n\\begin{tikzpicture}[\n  cell\u002F.style={draw, minimum width=11mm, minimum height=7mm, inner sep=2pt, font=\\small},\n  hd\u002F.style={minimum width=11mm, minimum height=7mm, inner sep=2pt, font=\\small},\n  >=stealth]\n  \\definecolor{acc}{HTML}{2348F2}\n  % header row\n  \\node[hd] (h0) at (0,0) {node};\n  \\node[hd] (h1) at (1.1,0) {$k{=}0$};\n  \\node[hd] (h2) at (2.2,0) {$k{=}1$};\n  \\node[hd] (h3) at (3.3,0) {$k{=}2$};\n  % rows: node 8 has parents 4 -> 2 -> 1\n  \\node[cell] at (0,-0.7) {$8$};\n  \\node[cell, draw=acc, text=acc] at (1.1,-0.7) {$4$};\n  \\node[cell] at (2.2,-0.7) {$2$};\n  \\node[cell, draw=acc, text=acc] at (3.3,-0.7) {$1$};\n  \\node[cell] at (0,-1.4) {$4$};\n  \\node[cell] at (1.1,-1.4) {$2$};\n  \\node[cell] at (2.2,-1.4) {$1$};\n  \\node[cell] at (3.3,-1.4) {$1$};\n  \\node[cell] at (0,-2.1) {$2$};\n  \\node[cell] at (1.1,-2.1) {$1$};\n  \\node[cell] at (2.2,-2.1) {$1$};\n  \\node[cell] at (3.3,-2.1) {$1$};\n\\end{tikzpicture}\n$$\n\nReading row $8$: its $1$st ancestor is $4$ ($k{=}0$), its $2$nd is $2$, its $4$th\nis $1$. To find the $5$th ancestor of $8$ we write $5 = 101_2$ and jump by the\n$k{=}0$ and $k{=}2$ columns — cells highlighted in `acc` — climbing $1$ then $4$\nedges; on this depth-$3$ tree that runs off the root, which $\\textsc{Kth-Ancestor}$\nreports as nil.\n\n## Application: tree distance and path queries\n\nLCA turns a two-vertex path question into arithmetic on depths. The unique path\nfrom $u$ to $v$ in a tree goes up from $u$ to $\\operatorname{lca}(u,v)$ and back\ndown to $v$, so its length is\n\n$$\n\\operatorname{dist}(u,v) = depth[u] + depth[v] - 2\\,depth\\bigl[\\operatorname{lca}(u,v)\\bigr].\n$$\n\nEach query is one LCA plus $O(1)$ work, hence $O(\\log n)$. The same decomposition\nanswers \"is $w$ on the $u\\!-\\!v$ path?\", aggregates a value along the path (split\ninto the two vertical legs), or, combined with $\\textsc{Kth-Ancestor}$, emits\nstep-by-step `U`\u002F`L`\u002F`R` directions: climb $depth[u] - depth[\\text{lca}]$ steps\nup, then walk the recorded downward path to $v$.\n\n## Alternatives\n\nBinary lifting is the most broadly useful LCA method, but two others are worth\nknowing.[^cprefs]\n\n- **Euler tour + sparse-table RMQ.** Record the Euler traversal of the tree (each\n  node appended on entry and after each child returns); within it, the LCA of $u$\n  and $v$ is the _shallowest_ node visited between any occurrence of $u$ and of\n  $v$. That reduces LCA to a [**range-minimum query**](\u002Falgorithms\u002Fdata-structures\u002Ffenwick-and-segment-trees) over the depth array, which a\n  sparse table answers in $O(1)$ after an $O(n\\log n)$ build.[^euler] So queries\n  drop to $O(1)$, but the structure is static and does not directly give $k$-th\n  ancestors.\n\n  The reduction is best seen laid out. Below the tree, the Euler tour writes each\n  node as it is entered and re-entered, with its depth underneath. The LCA of $u$\n  and $v$ is the **shallowest** entry anywhere between an occurrence of $u$ and one\n  of $v$ — i.e. the minimum of that depth subarray (shaded), which here is $a$:\n\n  $$\n  % caption: Euler tour reduces LCA to range-minimum: between $u$ and $v$ in the tour, the shallowest (minimum-depth) entry is $\\operatorname{lca}(u,v)=a$.\n  \\begin{tikzpicture}[font=\\small, >=Stealth, x=8.5mm]\n    \\definecolor{acc}{HTML}{2348F2}\n    % --- small tree ---\n    \\begin{scope}[every node\u002F.style={circle, draw, minimum size=6mm, inner sep=0pt, font=\\scriptsize}]\n      \\node (r) at (3,1.7) {$r$};\n      \\node (a) at (3,0.85) {$a$};\n      \\node (uu) at (2.3,0) {$u$};\n      \\node (vv) at (3.7,0) {$v$};\n      \\draw (r)--(a); \\draw (a)--(uu); \\draw (a)--(vv);\n    \\end{scope}\n    % shade the subarray between u (idx 2) and v (idx 4) -- drawn first, behind cells\n    \\fill[acc!16] (2-0.45,-1.35) rectangle (4+0.45,-0.65);\n    % --- euler tour array + depths ---\n    \\foreach \\lab [count=\\i from 0] in {r,a,u,a,v,a,r}\n      \\node[draw, minimum size=6mm, font=\\scriptsize] at (\\i,-1.0) {$\\lab$};\n    \\foreach \\dpt [count=\\i from 0] in {0,1,2,1,2,1,0}\n      \\node[font=\\scriptsize, gray] at (\\i,-1.75) {$\\dpt$};\n    % mark the minimum-depth entry (a at idx 3)\n    \\node[draw=acc, very thick, minimum size=6mm, inner sep=0] at (3,-1.0) {};\n    \\node[font=\\scriptsize, gray] at (-1.3,-1.0) {tour:};\n    \\node[font=\\scriptsize, gray] at (-1.3,-1.75) {depth:};\n    \\node[font=\\scriptsize, acc] at (3,-2.45) {min depth $=\\operatorname{lca}=a$};\n  \\end{tikzpicture}\n  $$\n- **Tarjan's offline LCA.** If all query pairs are known in advance, a single [DFS](\u002Falgorithms\u002Fgraphs\u002Frepresentations-and-traversal)\n  with a union-find structure answers them in near-linear $O((n+q)\\,\\alpha)$ total\n  time, processing each query when its second endpoint is first reached.[^tarjan]\n\n> **Remark (How to choose).** Binary lifting is **online** (queries may arrive one at a\n> time), needs only parent pointers and a DFS, answers in $O(\\log n)$, and is the\n> _only_ one of the three that also serves $k$-th-ancestor queries — at the cost\n> of $O(n\\log n)$ space. Reach for Euler+RMQ when you need $O(1)$ LCA on a fixed\n> tree, and Tarjan when every query is known up front and you want the lowest\n> total cost.\n\n## Takeaways\n\n- The **lowest common ancestor** of $u$ and $v$ is the deepest node ancestral to\n  both; it is unique because ancestor sets are root-chains.\n- The **naive walk** (equalize depth, climb together) needs no preprocessing but\n  costs $O(h)$ per query, or $\\Theta(n)$ on a degenerate tree.\n- **Binary lifting** precomputes $up[v][k]$, the $2^k$-th ancestor, via the\n  doubling identity $up[v][k] = up[\\,up[v][k-1]\\,][k-1]$ in $O(n\\log n)$ time and\n  space.\n- A **$k$-th-ancestor** query jumps by each $1$-bit of $k$; an **LCA** query\n  lifts the deeper node to equal depth, then jumps both up by decreasing powers of\n  two while they stay distinct — each $O(\\log n)$.\n- **Tree distance** is $depth[u] + depth[v] - 2\\,depth[\\operatorname{lca}(u,v)]$,\n  turning path queries into $O(\\log n)$ arithmetic.\n- Alternatives: **Euler tour + sparse-table RMQ** gives $O(1)$ queries on a static\n  tree; **Tarjan's** union-find DFS answers all queries offline in near-linear\n  time. Binary lifting wins on being online and also serving $k$-th ancestors.\n\n[^cprefs]: **Skiena**, § — Trees \u002F LCA: survey of LCA strategies and the preprocessing\u002Fquery trade-off across query models.\n[^euler]: **Erickson**, Ch. — Trees: the Euler-tour reduction of LCA to range-minimum, with sparse-table RMQ giving $O(1)$ queries after $O(n\\log n)$ preprocessing.\n[^tarjan]: **CLRS**, Ch. — (trees): Tarjan's offline LCA via depth-first search and disjoint-set union, near-linear in $(n+q)$.\n",{"text":7219,"minutes":7220,"time":7221,"words":7222},"8 min read",7.255,435300,1451,{"title":189,"description":7197},[7225,7227,7229],{"book":7132,"ref":7226},"Ch. — (trees)",{"book":7041,"ref":7228},"§ — Trees \u002F LCA",{"book":7055,"ref":7230},"Ch. — Trees","available","01.algorithms\u002F06.graphs\u002F07.lowest-common-ancestor",[153],"zX38vFme3mhlAdUKrqm2Dw9r8jMzpjBG4aZTkDf74zc",{"\u002Falgorithms\u002Ffoundations\u002Fwhat-is-an-algorithm":7236,"\u002Falgorithms\u002Ffoundations\u002Fasymptotic-analysis":7237,"\u002Falgorithms\u002Ffoundations\u002Frecurrences":7238,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fmergesort":7239,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fquicksort":7240,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fselection":7241,"\u002Falgorithms\u002Fsorting\u002Fheaps-and-heapsort":7242,"\u002Falgorithms\u002Fsorting\u002Fsorting-lower-bounds":7243,"\u002Falgorithms\u002Fsorting\u002Flinear-time-sorting":7244,"\u002Falgorithms\u002Fdata-structures\u002Felementary-structures":7245,"\u002Falgorithms\u002Fdata-structures\u002Fhash-tables":7246,"\u002Falgorithms\u002Fdata-structures\u002Fbinary-search-trees":7247,"\u002Falgorithms\u002Fdata-structures\u002Favl-trees":7248,"\u002Falgorithms\u002Fdata-structures\u002Fbalanced-trees":7249,"\u002Falgorithms\u002Fdata-structures\u002Funion-find":7250,"\u002Falgorithms\u002Fdata-structures\u002Ffenwick-and-segment-trees":7251,"\u002Falgorithms\u002Fsequences\u002Ftwo-pointers-and-windows":7252,"\u002Falgorithms\u002Fsequences\u002Fmonotonic-stacks":7253,"\u002Falgorithms\u002Fsequences\u002Fbinary-search-on-the-answer":7254,"\u002Falgorithms\u002Fsequences\u002Fstring-matching":7255,"\u002Falgorithms\u002Fsequences\u002Ftries":7256,"\u002Falgorithms\u002Fgraphs\u002Frepresentations-and-traversal":7257,"\u002Falgorithms\u002Fgraphs\u002Ftopological-sort-and-scc":7258,"\u002Falgorithms\u002Fgraphs\u002Fminimum-spanning-trees":7259,"\u002Falgorithms\u002Fgraphs\u002Fshortest-paths":7260,"\u002Falgorithms\u002Fgraphs\u002Fnetwork-flow":7261,"\u002Falgorithms\u002Fgraphs\u002Fbridges-and-articulation-points":7262,"\u002Falgorithms\u002Fgraphs\u002Flowest-common-ancestor":7222,"\u002Falgorithms\u002Fgraphs\u002Ftwo-sat":7263,"\u002Falgorithms\u002Fgraphs\u002Feulerian-tours":7264,"\u002Falgorithms\u002Fgreedy\u002Fthe-greedy-method":7265,"\u002Falgorithms\u002Fgreedy\u002Fscheduling-and-intervals":7266,"\u002Falgorithms\u002Fgreedy\u002Fhuffman-codes":7267,"\u002Falgorithms\u002Fgreedy\u002Fmatroids":7268,"\u002Falgorithms\u002Fdynamic-programming\u002Fprinciples":7269,"\u002Falgorithms\u002Fdynamic-programming\u002Fsequence-dp":7270,"\u002Falgorithms\u002Fdynamic-programming\u002Flongest-increasing-subsequence":7271,"\u002Falgorithms\u002Fdynamic-programming\u002Fknapsack":7272,"\u002Falgorithms\u002Fdynamic-programming\u002Fcoin-change-and-unbounded":7273,"\u002Falgorithms\u002Fdynamic-programming\u002Finterval-dp":7274,"\u002Falgorithms\u002Fdynamic-programming\u002Ftree-dp":7275,"\u002Falgorithms\u002Fdynamic-programming\u002Fbitmask-dp":7276,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-optimizations":7277,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-on-graphs":7278,"\u002Falgorithms\u002Fbacktracking\u002Fbacktracking-fundamentals":7279,"\u002Falgorithms\u002Fbacktracking\u002Fconstraint-search":7280,"\u002Falgorithms\u002Fbacktracking\u002Fbranch-and-bound":7281,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fnumber-theory-basics":7252,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fmodular-exponentiation-and-primality":7282,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fsieve-and-factorization":7283,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fcombinatorics":7284,"\u002Falgorithms\u002Fcomputational-geometry\u002Fgeometric-primitives":7285,"\u002Falgorithms\u002Fcomputational-geometry\u002Fconvex-hull":7267,"\u002Falgorithms\u002Fcomputational-geometry\u002Fsweep-line":7286,"\u002Falgorithms\u002Fintractability\u002Fp-np-reductions":7287,"\u002Falgorithms\u002Fintractability\u002Fnp-completeness":7248,"\u002Falgorithms\u002Fintractability\u002Fcoping-with-hardness":7288,"\u002Falgorithms":7289,"\u002Ftheory-of-computation":7290,"\u002Fcomputer-architecture":7290,"\u002Fphysical-computing":7290,"\u002Fdatabases":7290,"\u002Fdeep-learning":7290},1763,2107,1738,2628,1723,2048,1697,1044,1542,1565,1679,1586,1388,1465,1971,1455,1533,1483,1578,1791,1481,2704,1658,2070,1978,2080,1568,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":7292,"\u002Falgorithms\u002Ffoundations\u002Fasymptotic-analysis":7293,"\u002Falgorithms\u002Ffoundations\u002Frecurrences":7294,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fmergesort":7295,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fquicksort":7296,"\u002Falgorithms\u002Fdivide-and-conquer\u002Fselection":7297,"\u002Falgorithms\u002Fsorting\u002Fheaps-and-heapsort":7298,"\u002Falgorithms\u002Fsorting\u002Fsorting-lower-bounds":7299,"\u002Falgorithms\u002Fsorting\u002Flinear-time-sorting":7300,"\u002Falgorithms\u002Fdata-structures\u002Felementary-structures":7301,"\u002Falgorithms\u002Fdata-structures\u002Fhash-tables":7302,"\u002Falgorithms\u002Fdata-structures\u002Fbinary-search-trees":7303,"\u002Falgorithms\u002Fdata-structures\u002Favl-trees":7304,"\u002Falgorithms\u002Fdata-structures\u002Fbalanced-trees":7305,"\u002Falgorithms\u002Fdata-structures\u002Funion-find":7306,"\u002Falgorithms\u002Fdata-structures\u002Ffenwick-and-segment-trees":7307,"\u002Falgorithms\u002Fsequences\u002Ftwo-pointers-and-windows":7308,"\u002Falgorithms\u002Fsequences\u002Fmonotonic-stacks":7309,"\u002Falgorithms\u002Fsequences\u002Fbinary-search-on-the-answer":7310,"\u002Falgorithms\u002Fsequences\u002Fstring-matching":7311,"\u002Falgorithms\u002Fsequences\u002Ftries":7312,"\u002Falgorithms\u002Fgraphs\u002Frepresentations-and-traversal":7313,"\u002Falgorithms\u002Fgraphs\u002Ftopological-sort-and-scc":7314,"\u002Falgorithms\u002Fgraphs\u002Fminimum-spanning-trees":7315,"\u002Falgorithms\u002Fgraphs\u002Fshortest-paths":7316,"\u002Falgorithms\u002Fgraphs\u002Fnetwork-flow":7317,"\u002Falgorithms\u002Fgraphs\u002Fbridges-and-articulation-points":7318,"\u002Falgorithms\u002Fgraphs\u002Flowest-common-ancestor":7319,"\u002Falgorithms\u002Fgraphs\u002Ftwo-sat":7320,"\u002Falgorithms\u002Fgraphs\u002Feulerian-tours":7321,"\u002Falgorithms\u002Fgreedy\u002Fthe-greedy-method":7322,"\u002Falgorithms\u002Fgreedy\u002Fscheduling-and-intervals":7323,"\u002Falgorithms\u002Fgreedy\u002Fhuffman-codes":7324,"\u002Falgorithms\u002Fgreedy\u002Fmatroids":7325,"\u002Falgorithms\u002Fdynamic-programming\u002Fprinciples":7326,"\u002Falgorithms\u002Fdynamic-programming\u002Fsequence-dp":7327,"\u002Falgorithms\u002Fdynamic-programming\u002Flongest-increasing-subsequence":7328,"\u002Falgorithms\u002Fdynamic-programming\u002Fknapsack":7329,"\u002Falgorithms\u002Fdynamic-programming\u002Fcoin-change-and-unbounded":7330,"\u002Falgorithms\u002Fdynamic-programming\u002Finterval-dp":7331,"\u002Falgorithms\u002Fdynamic-programming\u002Ftree-dp":7332,"\u002Falgorithms\u002Fdynamic-programming\u002Fbitmask-dp":7333,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-optimizations":7334,"\u002Falgorithms\u002Fdynamic-programming\u002Fdp-on-graphs":7335,"\u002Falgorithms\u002Fbacktracking\u002Fbacktracking-fundamentals":7336,"\u002Falgorithms\u002Fbacktracking\u002Fconstraint-search":7337,"\u002Falgorithms\u002Fbacktracking\u002Fbranch-and-bound":7338,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fnumber-theory-basics":7339,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fmodular-exponentiation-and-primality":7340,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fsieve-and-factorization":7341,"\u002Falgorithms\u002Fmathematical-algorithms\u002Fcombinatorics":7342,"\u002Falgorithms\u002Fcomputational-geometry\u002Fgeometric-primitives":7343,"\u002Falgorithms\u002Fcomputational-geometry\u002Fconvex-hull":7344,"\u002Falgorithms\u002Fcomputational-geometry\u002Fsweep-line":7345,"\u002Falgorithms\u002Fintractability\u002Fp-np-reductions":7346,"\u002Falgorithms\u002Fintractability\u002Fnp-completeness":7347,"\u002Falgorithms\u002Fintractability\u002Fcoping-with-hardness":7348,"\u002Falgorithms":7349,"\u002Ftheory-of-computation":7352,"\u002Fcomputer-architecture":7355,"\u002Fphysical-computing":7358,"\u002Fdatabases":7361,"\u002Fdeep-learning":7364},{"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":7350,"title":7351,"module":376,"summary":376},"\u002Falgorithms","Algorithms",{"path":7353,"title":7354,"module":376,"summary":376},"\u002Ftheory-of-computation","Theory of Computation",{"path":7356,"title":7357,"module":376,"summary":376},"\u002Fcomputer-architecture","Computer Architecture",{"path":7359,"title":7360,"module":376,"summary":376},"\u002Fphysical-computing","Physical Computing",{"path":7362,"title":7363,"module":376,"summary":376},"\u002Fdatabases","Databases",{"path":7365,"title":7366,"module":376,"summary":376},"\u002Fdeep-learning","Deep Learning",1781560524684]