Draft:Difference array

This is an old revision of this page, as edited by Heyyo53 (talk | contribs) at 03:01, 22 May 2025 (Added information about use in steganalaysis, I am not too knowledgable of said subject but I provided a source. If someone knows more about it feel free to edit.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


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 . The main goal of a difference array is to show the amount of change between consecutive elements in an array.[1][2]

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  [2]

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.[2]

Range Queries

A difference array can be used to update an array that is being modified using range queries in constant time.[3] 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  . 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  .[4][1]

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.[3]

Proof

The relative differences of the values that lie within the range   will remain unchanged after a range query is performed. However the elements   and   will have their relative differences change. Since each element within   is increasing by   element   will be   greater than the previous entry, similarly element   will be x less than the next entry in the array.

 

 

 

Thus the middle x cancels out showing that   has no effect on the differences of the middle values.

Steganalaysis

Methods of JPEG base steganography can be detected using difference arrays. It has been shown that Markov features that were extracting from zigzag intra-block and inter-block difference array improve steganography detection substantially. By calculating difference arrays along the horizontal and vertical directions of the JPEG's data array, then applying a Markov matrix to these difference arrays intra-block features are able to be constructed.[5]

References

  1. ^ a b Laaksonen, Antti (2020-05-08). Guide to Competitive Programming: Learning and Improving Algorithms Through Contests. Springer Nature. p. 137. ISBN 978-3-030-39357-1.
  2. ^ a b c "Prefix sum array and difference array - PEGWiki". wcipeg.com. Retrieved 2025-05-20.
  3. ^ a b Katiyar, Ishank (2021-07-30). "Understanding Difference Array: The Underrated Constant Time Range Update Algorithm (Part 1)". Medium. Retrieved 2025-05-20.{{cite web}}: CS1 maint: url-status (link)
  4. ^ Nadaf, Aman (2023-02-28). "Difference Array Technique". TeckBakers. Retrieved 2025-05-20.{{cite web}}: CS1 maint: url-status (link)
  5. ^ Zhou, Zhiping; Hui, Maomao (2009-08). "Steganalysis for Markov Feature of Difference Array in DCT Domain". 2009 Sixth International Conference on Fuzzy Systems and Knowledge Discovery. 7: 581–584. doi:10.1109/FSKD.2009.230. {{cite journal}}: Check date values in: |date= (help)