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.

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

each student can attend the examinati<strong>on</strong> for each course that he has taken.<br />

This can always be arranged by allocating a separate sessi<strong>on</strong> for each examina-<br />

ti<strong>on</strong>; but the interests of examiner and student alike dictate that the total<br />

examinati<strong>on</strong> period be as short as possible. This means that each sessi<strong>on</strong><br />

should c<strong>on</strong>tain as many examinati<strong>on</strong>s as possible, subject to some limit k.<br />

An additi<strong>on</strong>al c<strong>on</strong>straint is imposed by the size of the examinati<strong>on</strong> hall,<br />

which can <strong>on</strong>ly accommodate a certain maximum number of students.<br />

Before designing the program, it is desirable to c<strong>on</strong>firm our understanding<br />

of the problem by making a more rigorous formalisati<strong>on</strong> in terms of the<br />

structure of the various items of data, both given and required. The types<br />

"student" and "exam" are obviously unstructured and need no further<br />

definiti<strong>on</strong> at this stage. The load of exams to be taken by each student is<br />

given by a mapping"<br />

load: array student of powerset exam.<br />

A timetable is a set of sessi<strong>on</strong>s, where each sessi<strong>on</strong> c<strong>on</strong>sists of a set of exams:<br />

type sessi<strong>on</strong> = powerset exam;<br />

timetable: powerset sessi<strong>on</strong>.<br />

We next attempt to formalise the properties which the input and output<br />

data are required to possess.<br />

(1) We choose not to formalise the c<strong>on</strong>diti<strong>on</strong> that the number of sessi<strong>on</strong>s<br />

be minimised, since in fact we do not want an absolute minimum if this<br />

turns out to be too expensive to compute.<br />

(2) Each exam is scheduled for <strong>on</strong>e of the sessi<strong>on</strong>s<br />

s = exam.all<br />

s ia timetable<br />

(3) No exam is scheduled for more than <strong>on</strong>e sessi<strong>on</strong>:<br />

s l, s2 in timetable = s l ^ s2 = { }<br />

C<strong>on</strong>diti<strong>on</strong>s (2) and (3) effectively state that the timetable is a partiti<strong>on</strong>ing<br />

of the set of all exams into exhaustive and exclusive subsets.<br />

(4) No sessi<strong>on</strong> includes more than k exams<br />

s in timetable ~ size (s) ~< k<br />

(5) No sessi<strong>on</strong> involves more than hallsize students. To formalise this,<br />

we need to count the number of students taking each exam:<br />

examcount (e:exam) = size (st:studentle in load (st)}.<br />

Now the number of students involved in a sessi<strong>on</strong> is<br />

sessi<strong>on</strong> count (s:sessi<strong>on</strong>) -- ~ examcount (e)<br />

eins

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

Saved successfully!

Ooh no, something went wrong!