Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 48s1 days 16 hours 1 minutes 48 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 48s1 days 16 hours 1 minutes 48 seconds.

Sign in to watch this lesson
Advanced - Trees · 4:48
Binary lifting stores, for every vertex, its ancestors 1, 2, 4, 8, ... levels up, each built as two jumps of the level below, in O(n log n) time and memory. A lowest-common-ancestor query lifts one vertex from the largest jump down while it stays below the other's ancestors, so it costs O(log n), and the same table gives distances, k-th ancestors and path aggregates. For trees that grow leaf by leaf under tight memory, Harel-Tarjan style jump pointers keep one pointer per vertex with O(1) work per new leaf.