Data Structures & AlgorithmsModerateICPC regional · tree data structures

Problem: Why can subtree queries on a rooted tree be answered with a range query on an array?

  1. A. Every subtree has exactly the same size
  2. B. The tree is always a path
  3. C. Subtree sums are stored in the root only
  4. D. An Euler tour assigns each subtree a contiguous range of entry and exit times

Correct answer: D. An Euler tour assigns each subtree a contiguous range of entry and exit times

In a DFS order, the nodes of a subtree occupy a contiguous interval, so any segment tree or Fenwick tree over the order answers subtree aggregates.

More Coding Interview Problems questions

Exams that ask this topic