Data Structures & AlgorithmsHardProduct Company SDE · data structures

Problem: What is the time complexity of building a Fenwick tree from an array of n values in O(n) time?

  1. A. Linear, by adding each value to its parent node once
  2. B. O(n log n) only
  3. C. O(n^2)
  4. D. Impossible in linear time

Correct answer: A. Linear, by adding each value to its parent node once

Each index pushes its value to i + lowbit(i) once, giving a linear-time build.

More Coding Interview Problems questions

Exams that ask this topic