Data Structures & AlgorithmsHardGATE CS · competitive programming

In a Fenwick tree with n = 16, an update at index 5 moves i ← i + (i & −i) while i ≤ n. How many tree nodes does the update touch?

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

Correct answer: B. 4

The indices visited are 5, 6, 8 and 16. Stepping by i ← i + 1 instead would touch 12 nodes, which is the wrong structure.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic