Which of the following best describes the main purpose of a Fenwick tree (Binary Indexed Tree)?
Think about what Fenwick trees help calculate quickly.
Fenwick trees are designed to efficiently compute prefix sums and update values in logarithmic time, making them useful for cumulative frequency calculations.
In a Fenwick tree, when updating the value at index i, which operation determines the next index to update?
Consider how the Fenwick tree moves upward to cover ranges.
The update operation moves to the next index by adding the least significant set bit of the current index, allowing it to cover all relevant ranges.
Given a Fenwick tree built over the array [3, 2, -1, 6, 5, 4, -3, 3, 7, 2, 3], what is the result of querying the prefix sum up to index 5 (1-based)?
array = [3, 2, -1, 6, 5, 4, -3, 3, 7, 2, 3] # Query prefix sum up to index 5
Sum the first 5 elements of the array.
The prefix sum up to index 5 is 3 + 2 + (-1) + 6 + 5 = 15.
Which of the following statements correctly compares Fenwick trees and segment trees?
Think about memory usage and query flexibility.
Fenwick trees are simpler and use less memory but mainly support prefix sums and point updates, while segment trees are more flexible but use more memory.
Consider a Fenwick tree indexed from 1 to n. If you perform a query for the prefix sum at index 0, what will happen?
Think about how prefix sums are defined starting at index 1.
Querying prefix sum at index 0 means summing zero elements, so the result is 0 without error.