Draft:Difference array: Difference between revisions

Content deleted Content added
Heyyo53 (talk | contribs)
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.
Citation bot (talk | contribs)
Alter: url, title, template type. URLs might have been anonymized. Add: isbn, chapter, authors 1-1. Removed URL that duplicated identifier. Removed parameters. Some additions/deletions were parameter name changes. | Use this bot. Report bugs. | #UCB_CommandLine
 
(7 intermediate revisions by 4 users not shown)
Line 1:
{{AFC submission|d|nn|u=Heyyo53|ns=118|decliner=ToadetteEditCoconutOctopus|declinets=2025052108473620250610091154|reason2=essay|ts=2025052023175720250523233053}} <!-- Do not remove this line! -->
{{AFC submission|d|nn|u=Heyyo53|ns=118|decliner=ToadetteEdit|declinets=20250521084736|small=yes|ts=20250520231757}} <!-- Do not remove this line! -->
 
{{Short description|Computer Science Algorithm}}
Line 7 ⟶ 8:
<!-- Important, do not remove anything above this line before article has been created. -->
 
 
An array that is constructed usingtakes a sequence of numbers <math>A=\{x_{0},x_{1},...,x_{n}\}</math> and stores the differences between each element formingin athe newarray. More generally an array <math>D(A)=y_{0},y_{1},...,y_{n}</math> in whichwhere <math>y_{i}=x_{i}-x_{i-1}</math>. The difference array of a sequence <math>A</math> can be denoted as <math>D(A)</math>. The main goal ofCommonly a difference array is use to showmake thea amountseries of changerange betweenqueries consecutivewith elementsconstant in[[time an array.complexity]]<ref name=":2">{{Cite book |last=Laaksonen |first=Antti |url=https://wwwbooks.google.com/books/edition/Guide_to_Competitive_Programming/3JbiDwAAQBAJ?hlid=en&gbpv=03JbiDwAAQBAJ |title=Guide to Competitive Programming: Learning and Improving Algorithms Through Contests |date=2020-05-08 |publisher=Springer Nature |isbn=978-3-030-39357-1 |publication-date=2020-05-08 |pages=137 |language=en}}</ref><ref name=":0">{{Cite web |title=Prefix sum array and difference array - PEGWiki |url=https://wcipeg.com/wiki/Prefix_sum_array_and_difference_array |access-date=2025-05-20 |website=wcipeg.com}}</ref>
 
<math>\begin{array}{l}
Line 16 ⟶ 18:
\end{array}</math>
 
== Inverse FunctionProperties ==
 
=== Inverse Function ===
A difference array can be undone using a prefix sum array. Here the prefix sum array is denoted as <math>P(c, A)</math> where <math>c</math> is an arbituary constant prepending the prefix sum array. Given that <math>c</math> is <math>A_0</math> by plugging into the prefix sum function <math>P(A_0, D(A))=A</math><ref name=":0" />
 
=== Uniqueness of Difference Arrays ===
<math>A</math> only has a single difference array <math>D(A)</math>. If no additional inputs are given <math>D(A)</math> uses the elements of <math>A</math> to form the difference array. The non-communativity of subtraction only allows for single way to represent a given difference array.<ref name=":0" />
 
== Range QueriesUsage ==
 
A difference array can be used to update an array that is being modified using range queries in constant time.<ref name=":1">{{Cite web |last=Katiyar |first=Ishank |date=2021-07-30 |title=Understanding Difference Array: The Underrated Constant Time Range Update Algorithm (Part 1) |url=https://medium.com/@ishankkatiyar162/understanding-difference-array-the-underrated-constant-time-range-update-algorithm-part-1-e432ada7f1f5 |url-status=live |access-date=2025-05-20 |website=Medium}}</ref> Here a query <math>(l, r, x)</math> with <math>l, r</math> as the left and right indices of the array to edit and <math>x</math> as the value to add to the elements within <math>[l,r]</math>. 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 <math>[l,r]</math> the elements of <math>D(A)</math> will remain unchanged except for <math>D(A)[l], D(A)[r]</math> which will be <math>x</math> more than before the query. This allows for a range query to be expressed by <math>D(A)[l]+1</math> and <math> D(A)[r+1]-1</math>.<ref>{{Cite web |last=Nadaf |first=Aman |date=2023-02-28 |title=Difference Array Technique |url=https://teckbakers.hashnode.dev/difference-array-technique |url-status=live |access-date=2025-05-20 |website=TeckBakers}}</ref><ref name=":2" />
=== Range Queries ===
[[Range Queries|Range queries]] are an array modifying operation that add a value to a defined range of values
 
<math>(l, r, x)</math>
 
* <math>l, r</math> Left and right indices of the range of elements to edit (inclusive).
* <math>x</math> Value to add to the elements within <math>[l,r]</math>.
 
ADifference differencearrays array can beare used to update an arrayarrays that is beingare modified using [[Range Queries|range queries]] inwithin [[constant time]].<ref name=":1">{{Cite web |last=Katiyar |first=Ishank |date=2021-07-30 |title=Understanding Difference Array: The Underrated Constant Time Range Update Algorithm (Part 1) |url=https://medium.com/@ishankkatiyar162/understanding-difference-array-the-underrated-constant-time-range-update-algorithm-part-1-e432ada7f1f5 |url-status=live |access-date=2025-05-20 |website=Medium}}</ref> Here a query <math>(l, r, x)</math> with <math>l, r</math> asinitially the left and right indices of thedifference array tohas editeach and <math>x</math> as theelement valueset to add to the elements within <math>[l,r]</math>0. Difference arrays exhibit a unique property where when modified withusing a range query only require changes to the elements that lie on the bounds of saidthe queryrange are modifyquery. So given thea range query of <math>[(l, r], x)</math> the elements of <math>D(A)</math> will remain unchanged except for at index <math>D(A)[l], D(A)[r]</math> which will beand <math>xr + 1</math> more than before the query. This allows for athe entire range query to be expressed by modifying <math>D(A)[A_{l]}+1</math> and <math> D(A)[A_{r+1]}-1</math> rather than updating each element between.<ref>{{Cite web |last=Nadaf |first=Aman |date=2023-02-28 |title=Difference Array Technique |url=https://teckbakers.hashnode.dev/difference-array-technique |url-status=live |access-date=2025-05-20 |website=TeckBakers}}</ref><ref name=":2" />
 
<math>D(A)=[0,0,0,0,0] \underbrace{\to}_{(l,r,x)}
\begin{array}{l}
D(A)[l] = 1 \\
D(A)[r+1] = -1 \\
\end{array}</math>
 
ToBy obtain the final arrayperforming a prefix sum can be performed on <math>D(A)</math>, thenonce whenadded the prefix sum ofto <math>D(A)</math> in where each matching index is added to <math>A</math>the allothers, the queriesresulting thatarray werewill tobe beingas appliedif each query was performed. This allows for any number of queries to <math>A</math> willto be performed throughwithin a single iteration.<ref name=":1" />
 
==== Proof ====
The relative differences of the values that lie within the range <math>(l,r)</math> will remain unchanged after a range query is performed. However the elements <math>l - 1</math> and <math>r + 1</math> will have their relative differences change. Since each element within <math>[l,r]</math> is increasing by <math>x</math> element <math>l</math> will be <math>x</math> greater than the previous entry, similarly element <math>r</math> will be x less than the next entry in the array.
 
Line 42 ⟶ 61:
Thus the middle x cancels out showing that <math>x</math> 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.<ref>{{Cite journalbook |lastlast1=Zhou |firstfirst1=Zhiping |last2=Hui |first2=Maomao |date=2009-08 |titlechapter=Steganalysis for Markov Feature of Difference Array in DCT Domain |urldate=https://ieeexplore.ieee.org/document/5360076August 2009 |journaltitle=2009 Sixth International Conference on Fuzzy Systems and Knowledge Discovery |volume=7 |pages=581–584 |doi=10.1109/FSKD.2009.230 |isbn=978-0-7695-3735-1 }}</ref>
 
== References ==