Jump to content

Sparse array

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 62.107.9.206 (talk) at 20:34, 1 June 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Arrays are datastructures used in programming languages. They map integer positions, or indices, less than the array's length, to values. A typical implementation allocates space for the entire array, even if only some indices are ever used.

A sparse array is an array where only very few indices are used. If this is known in advance, more space-efficient implementations can be used, which only allocates space for the entries that are actually used.

Example: An array with length one million, where only the indices 1, 3, 120 and 999999 are used is sparse. It would be inefficient to allocate any space for the remaining 999996 possible array elements.