Draft:Difference Array
![]() | Review waiting, please be patient.
This may take 3 months or more, since drafts are reviewed in no specific order. There are 2,846 pending submissions waiting for review.
Where to get help
How to improve a draft
You can also browse Wikipedia:Featured articles and Wikipedia:Good articles to find examples of Wikipedia's best writing on topics similar to your proposed article. Improving your odds of a speedy review To improve your odds of a faster review, tag your draft with relevant WikiProject tags using the button below. This will let reviewers know a new draft has been submitted in their area of interest. For instance, if you wrote about a female astronomer, you would want to add the Biography, Astronomy, and Women scientists tags. Editor resources
Reviewer tools
|
An array that is constructed using a sequence of numbers and the differences between each element forming a new array in which . The difference array of can be denoted as [1]
Inverse Function
A difference array can be undone using a prefix sum array. Here the prefix sum array is denoted as where is an arbituary constant prepending the prefix sum array. Given that is by plugging into the prefix sum function [1]
Uniqueness of Difference Arrays
only has a single difference array . If no additional inputs are given uses the elements of to form the difference array. The non-communativity of subtraction only allows for single way to represent a given difference array.[1]
Range Queries
A difference array can be used to update an array that is being modified using range queries in constant time.[2] Here a query with as the left and right indices of the array to edit and as the value to add to the elements within .[3] Difference arrays exhibit a unique property where when modified with a range query only the bounds of said query are modify. So given the range the elements of will remain unchanged except for which will be more than before the query. This allows for a range query to be expressed by and .
To obtain the final array a prefix sum can be performed on , then when the prefix sum of is added to all the queries that were to being applied to will be performed through a single iteration.[2]
References
- ^ a b c "Prefix sum array and difference array - PEGWiki". wcipeg.com. Retrieved 2025-05-20.
- ^ a b Katiyar, Ishank (Jul, 30, 2021). "Understanding Difference Array: The Underrated Constant Time Range Update Algorithm (Part 1)". Medium. Retrieved May, 20, 2025.
{{cite web}}
: Check date values in:|access-date=
and|date=
(help)CS1 maint: url-status (link) - ^ Nadaf, Aman (Feb / 28 / 2023). "Difference Array Technique". TeckBakers. Retrieved May, 20, 2025.
{{cite web}}
: Check date values in:|access-date=
and|date=
(help)CS1 maint: url-status (link)