Draft:Difference array

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search


An array that takes a sequence of numbers A={x0,x1,...,xn} and stores the differences between each element in the array. More generally an array D(A)=y0,y1,...,yn where yi=xixi1. The difference array of a sequence A can be denoted as D(A). Commonly a difference array is use to make a series of range queries with constant time complexity:[1][2]

y0=x0y1=x1x0yn=xnxn1

Properties

[edit | edit source]

Inverse Function

[edit | edit source]

A difference array can be undone using a prefix sum array. Here the prefix sum array is denoted as P(c,A) where c is an arbituary constant prepending the prefix sum array. Given that c is A0 by plugging into the prefix sum function P(A0,D(A))=A.[2]

Uniqueness of Difference Arrays

[edit | edit source]

A only has a single difference array D(A). If no additional inputs are given D(A) uses the elements of A to form the difference array. The non-communativity of subtraction only allows for single way to represent a given difference array.[2]

Usage

[edit | edit source]

Range Queries

[edit | edit source]

Range queries are an array modifying operation that add a value to a defined range of values

(l,r,x)

  • l,r Left and right indices of the range of elements to edit (inclusive).
  • x Value to add to the elements within [l,r].

Difference arrays are used to update arrays that are modified using range queries within constant time.[3] initially the difference array has each element set to 0. Difference arrays when modified using a range query only require changes to the elements that lie on the bounds of the range query. So given a range query of (l,r,x) the elements of D(A) will remain unchanged except for at index l and r+1 . This allows for the entire range query to be expressed by modifying Al+1 and Ar+11 rather than updating each element between.[4][1]

D(A)=[0,0,0,0,0](l,r,x)D(A)[l]=1D(A)[r+1]=1

By performing a prefix sum on D(A), once added to A in where each matching index is added to the others, the resulting array will be as if each query was performed. This allows for any number of queries to A to be performed within a single iteration.[3]

Proof

[edit | edit source]

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

A=[a1,a2,a3,a4,a5](2,4,x)[a1,a2+x,a3+x,a4+x,a5]

D(A)=[a1,(a2a1)+x,(a3a2)+x,(a4a3)+x,a5a4]

D(A)[2]=(a2a1)+xD(A)[3]=(a3a2)+x=(a3((a2a1)+x)+x=a3(a2a1)x+x=a3a2+a1

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

Steganalaysis

[edit | edit source]

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

[edit | edit source]
  1. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  2. ^ a b c Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  3. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).