Abstract
- Prefix sum is an Array that has the same length as a given array
- The value at each index is the sum of values from the first element of the given array to the element at the current index
- Range Sum Query enables us to calculates the sum of a particular range of a given array efficiently by leveraging on Memoization
Range Sum Query
- With one-time computation of the Prefix Sum (前缀和) in , we can retrieve the sum of elements in a Contiguous Segment in
- , because
Tip
is same as . So we can just retrieve the value from the prefix sum array with index , instead of using the formula stated in the diagram above, which requires us to have a placeholder at index .