A(n) (less?) intuitive way to LCA with Euler Tour and Segment Tree

Revision en1, by SnoopyCodes, 2024-07-15 08:09:15

So, a few months ago, I was working on Euler Tour from the usaco guide website. There, they explained how you could compress a tree into an array of start[] and end[] arrays to build a segment tree on top of it. However, with LCA, they built a RMQ segtree off of the full inorder traversal of the tree, which confused me greatly. After all, in the examples of summing subtrees and updating vertexes, we hadn't needed to do that. Additionally, I was still greatly uncomfortable with changing the size of the segtree, and a segtree with 2 * (2n — 1) memory (I use the iterative version) pissed me off. I didn't do anymore problems on euler tour after that.

Now, however, I returned. The most annoying thing, in my opinion, was how the start[] and end[] arrays were combined so the segtree could be built. Indeed, in my code I wrote the following:

formatting

So, I present a way to build the segtree off of only the start[] array.

written for CSES Company Queries II
Tags euler tour, lca/rmq, segtree

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en9 English SnoopyCodes 2024-07-15 20:06:25 0 (published)
en8 English SnoopyCodes 2024-07-15 20:05:24 0 Tiny change: 'all 2 * N — 1 nodes. ' -> 'all 2 * N - 1 nodes. '
en7 English SnoopyCodes 2024-07-15 19:30:41 42 Tiny change: 's\n~~~~~\n\n</spoile' -> 's\n~~~~~\n</spoile'
en6 English SnoopyCodes 2024-07-15 19:09:46 985
en5 English SnoopyCodes 2024-07-15 17:31:24 70
en4 English SnoopyCodes 2024-07-15 08:52:38 1090 Tiny change: 'n</spoiler\n\n<spoil' -> 'n</spoiler>\n\n<spoil'
en3 English SnoopyCodes 2024-07-15 08:32:19 78 Tiny change: 'example.\nPicture\nThe corr' -> 'example.\n\nPicture\n\nThe corr'
en2 English SnoopyCodes 2024-07-15 08:29:50 1696 Tiny change: 'ths):\n\n</spoiler su' -> 'ths):\n\n<spoiler su'
en1 English SnoopyCodes 2024-07-15 08:09:15 2691 Initial revision (saved to drafts)