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.

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

The array provides a method of representing a particular arrangement of<br />

cards in a pack, since each arrangement may be regarded as a mapping which<br />

indicates for each of the fifty-two possible positi<strong>on</strong>s in a pack the value of the<br />

card which occupies that positi<strong>on</strong>. Thus each possible arrangement may be<br />

regarded as a value of the mapping type:<br />

type cardpack = array 1.. 52 of cardface.<br />

Of course, not all values of this type represent actual cardpacks, since there is<br />

nothing to prevent some value of the type from mapping two different<br />

positi<strong>on</strong>s <strong>on</strong>to the same card; which in real life is impossible.<br />

Arrays with elements that are of Cartesian product type are sometimes<br />

known as tables.<br />

A third example of an array is that which represents all possible c<strong>on</strong>-<br />

figurati<strong>on</strong>s of character punching <strong>on</strong> a c<strong>on</strong>venti<strong>on</strong>al punched card. This<br />

may be regarded as a mapping M which maps each column number into a<br />

character, namely the character punched in that column.<br />

type punchcard = array 1.. 80 of character.<br />

Any possible text punched into a card may be regarded as a single value of<br />

type punchcard.<br />

A fourth example shows an array which represents a possible value of a<br />

page <strong>on</strong> a cathode ray tube display device. There are assumed to be 40 rows<br />

and 27 character positi<strong>on</strong>s in each row. The effect of two dimensi<strong>on</strong>s can be<br />

achieved by specifying the domain of the mapping as a Cartesian product of<br />

the possible rows and the possible character positi<strong>on</strong>s within each row. This<br />

is written as follows"<br />

type spot = (row:l.. 40; column :l.. 27);<br />

type display page = array spot of character.<br />

An alternative method of dealing with a multidimensi<strong>on</strong>al array is to<br />

regard it as an array of rows, where each row is an array of characters"<br />

type display page = array I..40 of row;<br />

type row = array 1..27 of character.<br />

This is a more suitable abstract structure if the rows are to be processed<br />

separately and the columns are not.<br />

The cardinality of an array type is computed by raising the cardinality<br />

of the range type to the power of the cardinality of the domain type, i.e.<br />

cardinality (D -~ R) = cardinality (R) cardinality (D)<br />

This may be proved by c<strong>on</strong>sidering the number of decisi<strong>on</strong>s which have to<br />

be made to specify completely a value of an array type. For each value of<br />

the domain we have to choose between cardinality (R) possible values of the<br />

range type. We have to make such a choice independently for each element<br />

of the array, that is cardinality (D) times.

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

Saved successfully!

Ooh no, something went wrong!