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.

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

and <strong>on</strong> receipt of a newpage character, this should be output to a display<br />

device by the instructi<strong>on</strong><br />

outpage.<br />

The display device does not recognise the characters newline or newpage;<br />

c<strong>on</strong>sequently the ends of Iines and pages have to be filled up with spaces.<br />

Write a program in a suitable language to perform this operati<strong>on</strong>, using a<br />

selecti<strong>on</strong> of representati<strong>on</strong>s for the display page, e.g.<br />

unpacked<br />

loosely packed<br />

tightly packed<br />

indirect.<br />

Rewrite the program, using different representati<strong>on</strong>s. Compare the lengths<br />

and speeds of the code and data involved in the different representati<strong>on</strong>s.<br />

Write the corresp<strong>on</strong>ding programs to read a page from the display, and<br />

output the individual characters, taking care to eliminate redundant spaces<br />

at the ends of each line and blank lines at the end of each page wherever<br />

possible.<br />

7. THE POWERSET<br />

The powerset of a given set is defined as the set of all subsets of that set;<br />

and a powerset type is a type whose values are sets of values selected from<br />

some other type known as the base of the powerset. For example, the primary<br />

colours have been defined by enumerati<strong>on</strong> as red, yellow and blue. The<br />

other main colours are made up as a mixture of two or three of these colours:<br />

orange is a mixture of red and yellow; brown is a mixture of all three primary<br />

colours. Thus each main colour (including the primary colours) can be<br />

specified as that subset of the primary colours out of which it can be mixed.<br />

For example, orange may be regarded as the set with just two members,<br />

red and yellow. Using the traditi<strong>on</strong>al notati<strong>on</strong> for sets defined by enumerati<strong>on</strong>,<br />

this may be written: {red, yellow}. The pure colour red may be regarded as<br />

the set whose <strong>on</strong>ly member is the primary colour red, i.e. {red }. In this way it<br />

is possible to represent the seven main colours, red, orange, yellow, green,<br />

blue, purple and brown. When no primary colour is present (i.e. the null or<br />

empty set) this may be regarded as denoting the absence of colour, i.e.<br />

perhaps white. The type whose values range over the colours may be declared<br />

as the power set of the type primary colour:<br />

type colour = powerset primary colour.<br />

A sec<strong>on</strong>d example is provided by c<strong>on</strong>sidering a data structure required to<br />

represent the status of the request butt<strong>on</strong>s in a lift. A simple variable of type

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

Saved successfully!

Ooh no, something went wrong!