Data Structures & AlgorithmsModerateICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 42→60, 13→40, 10→42, 19→10, 8→19, 8→75, 42→77, 77→13. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 2nd ancestor of node 13?

  1. A. 42
  2. B. 77
  3. C. 10
  4. D. 8

Correct answer: A. 42

The 2nd ancestor is reached by 2 parent steps from 13; binary lifting takes the bits of 2 as jumps. Off by one in the step count, or treating 2 as an absolute depth, gives the trap nodes.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic