Algorithm and Data Structure - Array 02 Prefix Sum Array

Algorithm and Data Structure - Array 02 Prefix Sum Array

Posted by Leonard Meng on June 10, 2020

What is prefix sum array?

Prefix Sum array is a data structure design which helps us to answer several queries such as sum in a given range in constant time which would otherwise take linear time. It requires a linear time preprocessing and is widely used due to its simplicity and effectiveness. $^{[1]}$

The application of prefix sum array

Range Sum Query

For example, 303. Range Sum Query - Immutable, in this problem, without prefix array we have to sum the array every time when we call sumRange function.

Referencxe List

[1] https://iq.opengenus.org/prefix-sum-array/

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Welcome to reprint, and please indicate the source: Lingjun Meng's Blog Keep the content of the article complete and the above statement information!