Data Structures & AlgorithmsModerateICPC regional · Codeforces Div2 D

A rooted tree has these parent→child edges: 33→59, 27→38, 59→27, 25→85, 78→33, 85→76, 27→25. The parent of a node is its 1st ancestor. Using binary lifting, which node is the 2nd ancestor of node 76?

  1. A. 85
  2. B. 27
  3. C. 25
  4. D. 59

Correct answer: C. 25

The 2nd ancestor is reached by 2 parent steps from 76; 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