Apex › Storage & databases

Cartesian tree — where range-minimum is lowest-common-ancestor

A binary tree built from an array that is simultaneously a min-heap by value and a BST by index. Its defining trick: the minimum of any range a[i..j] is the lowest common ancestor of positions i and j — so range-minimum and LCA are the same problem, the equivalence that unlocks O(n)-build/O(1)-query RMQ. Drag a range and watch its minimum light up as the LCA.

More in Storage & databases