20.03.2013 Views

II. Notes on Data Structuring * - Cornell University

II. Notes on Data Structuring * - Cornell University

II. Notes on Data Structuring * - Cornell University

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

152 c.A.R. HOARE<br />

10.1.1. Sequential Representati<strong>on</strong><br />

The simplest representati<strong>on</strong> of a sparse array type is as a sequence of entries;<br />

i.e.<br />

sparse array D of R<br />

is represented as if it had been declared<br />

(default: R; s: sequence (key: D; informati<strong>on</strong>: R)).<br />

One of the possible sequence representati<strong>on</strong>s must now be chosen, in<br />

accordance with the same criteria that are used in the case of a sequence.<br />

But when a sequence is used to represent a sparse array, the order of the<br />

entries is immaterial, and does not have to reflect the relative times at which<br />

the entries were made. Thus the entries are often sorted into order of their<br />

key-value, particularly if this is the order in which they are going to be<br />

scanned.<br />

The chief disadvantage of the sequential representati<strong>on</strong> is the length of<br />

time taken to access the element corresp<strong>on</strong>ding to a random subscript. In<br />

the case of structures of any great size, the program designer usually goes to<br />

c<strong>on</strong>siderable trouble to ensure that entries are accessed in the same standard<br />

order that they are stored in the sequence; and that if new entries are to be<br />

inserted, these are also sorted and then merged with the original sequence.<br />

Thus the standard commercial practice of batch processing and updating of<br />

sequential files may be regarded as a practical implementati<strong>on</strong> of the abstract<br />

c<strong>on</strong>cept of a sparse array <strong>on</strong> the rather unsympathetic medium of magnetic<br />

tape.<br />

10.1.2. Tabular Representati<strong>on</strong><br />

If there is an acceptably low upper limit N to the number of entries in a<br />

sparse mapping, a great increase in speed of lookup can be achieved by the<br />

tabular representati<strong>on</strong>, in which the sparse mapping<br />

sparse array D of R<br />

is represented as a n<strong>on</strong>sparse array"<br />

(default: R; occupied: powerset 0.. N;<br />

array 0.. N of (key: D; informati<strong>on</strong>: R)).<br />

If all the significant entries are collected before they are used, the table can<br />

be sorted, and ther the entry with a given key can be rapidly located by<br />

logarithmic search.<br />

If access to the elements of the array is interleaved with additi<strong>on</strong> of new<br />

entries, some form of hash-table technique is indicated. For this an arbitrary<br />

"hashing" functi<strong>on</strong> is chosen, which maps the domain type D into an<br />

integer in the range 0..N. When the entry is inserted, it is placed at this<br />

positi<strong>on</strong> in the table; so whenever that entry is accessed, use of the same<br />

hashing functi<strong>on</strong> will find it there. If that positi<strong>on</strong> is already occupied by an

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!