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.

NOTES ON DATA STRUCTURING 151<br />

A similar example may arise in the descripti<strong>on</strong> of family relati<strong>on</strong>ship<br />

am<strong>on</strong>g pers<strong>on</strong>s:<br />

type children = sparse array (mother, father: pers<strong>on</strong>) of<br />

sparse powerset pers<strong>on</strong>:<br />

This array caters for multiple marriages better than the more tree-like<br />

representati<strong>on</strong>s of a family, which can be defined as a recursive structure.<br />

In the case of sparse arrays, it is sometimes useful to regard them as<br />

partial rather than total mappings. A partial mapping is <strong>on</strong>e which does not<br />

necessarily give a value for each member of its domain type. In other words,<br />

the actual domain over which it is defined is a subset of the domain type.<br />

For such an array type it is necessary to introduce an additi<strong>on</strong>al c<strong>on</strong>stant<br />

omega, denoting a mapping which is everywhere undefined. It is also useful<br />

to introduce a functi<strong>on</strong><br />

domain (x)<br />

which delivers as result the set of subscripts for elements of x which are<br />

actually defined. Thus the programmer can sequence through all the defined<br />

elements, or test whether a particular element is defined or not. Many of the<br />

examples quoted above might well have been declared as partial instead of<br />

sparse. In the case of a partial mapping, the default value does not have to be<br />

recorded.<br />

10.1 REPRESENTATION<br />

Sparse sets and arrays are usually represented by simply keeping a record<br />

of the default value and those members or elements which are significant;<br />

thus the representati<strong>on</strong> borrows techniques which are used in the case of the<br />

sequence type to deal with structures of changeable size. A sparse set may be<br />

regarded as a special case of a sparse mapping, which maps all its members<br />

<strong>on</strong>to the Boolean value true, and all its n<strong>on</strong>-members <strong>on</strong>to the default value<br />

false. Thus their representati<strong>on</strong>s are closely similar to those of sparse arrays,<br />

and do not require separate treatment.<br />

A sparse mapping c<strong>on</strong>sists of a number of elements. Each element<br />

of the mapping is represented as the Cartesian product of its subscript and<br />

its value; in this case the subscript is known as the key, and the value is<br />

known as the informati<strong>on</strong> associated with the element, and the juxtapositi<strong>on</strong><br />

of the two will be known as an entry. In the case of a set which is sparse,<br />

there is no need to record any informati<strong>on</strong>, since the presence of the key<br />

itself is sufficient to indicate that this value is a member of the set. Thus an<br />

entry for a sparse set c<strong>on</strong>sists <strong>on</strong>ly of a key.

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

Saved successfully!

Ooh no, something went wrong!