Data Structures & AlgorithmsHardGoogle · Trees

A Fenwick (binary indexed) tree over indices 1 to 16 is used. Updating position 5 touches the nodes 5, 6, 8, 16 (add the lowest set bit each time). How many nodes does the prefix-sum query for index 13 read?

  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 5

Correct answer: B. 3

Query subtracts the lowest set bit each step: 13 -> 12 -> 8 -> 0, reading nodes 13, 12 and 8.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic