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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

NOTES ON DATA STRUCTURING 125<br />

(11) Range (a, b) is the set c<strong>on</strong>taining a, succ(a),..., b if a ~< b, and which<br />

is empty otherwise.<br />

The most useful selective updating operati<strong>on</strong>s <strong>on</strong> sets are:<br />

x'v y; join the set y to x<br />

x:v T(a) add the member a to x<br />

x: ^ y; exclude from x all members which are not also members<br />

ofy<br />

x:- y exclude from x all members which are also members<br />

ofy<br />

x: down n subtract n from every member ofx and exclude members<br />

for which this is not possible<br />

x:up n add n to every member of x, and exclude members for<br />

which this is not possible<br />

It is also sometimes useful to select some member from x and simultaneously<br />

remove it from x. This operati<strong>on</strong> can be expressed by the notati<strong>on</strong>"<br />

a from x.<br />

If the domain type of x is ordered, it is natural that the selected member<br />

should be the minimum member of x; otherwise the selecti<strong>on</strong> should be<br />

regarded as arbitrary.<br />

It is often useful to define the value of a set by giving some c<strong>on</strong>diti<strong>on</strong> B<br />

which is satisfied by just those values of the domain type which are intended<br />

to be members of the set. This may be denoted:<br />

{i:OrB}<br />

where i is a variable of type D regarded as local to B,<br />

and B is a Boolean expressi<strong>on</strong> usually c<strong>on</strong>taining and depending <strong>on</strong> i.<br />

In order for this expressi<strong>on</strong> to denote a value of the powerset type it is<br />

essential that the cardinality of D be finite, and that B is defined over all<br />

values of the type.<br />

Finally, it is frequently required to perform some operati<strong>on</strong> <strong>on</strong> each<br />

member of some set, that is to execute a loop with a counting variable which<br />

takes <strong>on</strong> successively all values in the set. A suitable notati<strong>on</strong> for expressing<br />

this is:<br />

for x in s do...<br />

If the base type of s is an ordered type, it seems reas<strong>on</strong>able to postulate that<br />

the elements will be taken in the natural order, starting with the lowest.<br />

For an unordered base type, the programmer does not care in which order<br />

the members are taken, and he leaves open the opti<strong>on</strong> to choose an order<br />

that c<strong>on</strong>tributes best to efficiency.

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

Saved successfully!

Ooh no, something went wrong!