Take the 2-minute tour ×

Let's say I have an array of 100 random integers values. Instead of storing them plainly as they are, I can instead store the first, and put the distance between each consecutive integer.

How is this method called ?

I know this method seems completely worthless, but it could be useful for storing 3D model data, where consecutive vertices stored next to each other actually are very close: instead of using 32 bits, I could use a array of 8 bit integer.

share|improve this question
I'm not following what you mean by distance between them...are you referring to bytes in memory? Or the difference between value n and n+1? –  MGZero Feb 28 '12 at 14:16
Sounds like relative encoding. –  Mathew Hall Feb 28 '12 at 14:17
He means distance between numbers. There is mathematical definition of distance - it's |a - b|. –  Griwes Feb 28 '12 at 14:18
This doesn't have anything do with C and C++. –  Lundin Feb 28 '12 at 14:23
Retagged with algorithm instead of C / C++ since this seems language agnostic and we are talking about a method of encoding. –  Matthieu M. Feb 28 '12 at 14:27

1 Answer 1

up vote 15 down vote accepted

I believe you're looking for delta encoding:

Delta encoding is a way of storing or transmitting data in the form of differences between sequential data ...

Perhaps the simplest example is storing values of bytes as differences (deltas) between sequential values, rather than the values themselves. So, instead of 2, 4, 6, 9, 7, we would store 2, 2, 2, 3, −2.

share|improve this answer
Side note: I am very far from being an expert, but I believe many modern digital video compression codecs use this concept to compress video: storing a frame of video whole, called a keyframe, and then storing the differences between two frames from then on (with a new keyframe every now and then). –  dotnetengineer Feb 28 '12 at 15:25
@dotnetengineer Modern video codecs are even more complex than that! Some have three types of frames: "L" which are standalone frames, "P" which can use previous frames, and "B" which are bi-directional. Furthermore! They don't even need to use entire frames but rather spacial regions called "slices". That is why if you crop an H264 video between L frames and don't re-encode it you see up to a few seconds of weird colored rectangles moving around. –  nwellcome Feb 28 '12 at 15:35
@nwellcome Good to know :) Thanks for the clarification. I guess my original point, though, that delta encoding is an important concept for digital video compression, is still correct? –  dotnetengineer Feb 28 '12 at 18:46
@dotnetengineer Oh yes very correct, delta encoding is potentially useful any time you have sequential data and a video as a sequence of images is a great example. –  nwellcome Feb 28 '12 at 21:14

Your Answer


