II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
158 c.A.R. HOARE<br />
individual sessi<strong>on</strong>s, and do not menti<strong>on</strong> the timetable at all. This suggests<br />
that the program can be structured as an inner part which selects a suitable<br />
sessi<strong>on</strong> satisfying (4) (5) and (6), and an outer loop which c<strong>on</strong>structs the<br />
timetable out of such suitable sessi<strong>on</strong>s.<br />
The objective of the outer loop is to achieve satisfacti<strong>on</strong> of c<strong>on</strong>diti<strong>on</strong>s (2)<br />
and (3) <strong>on</strong> its completi<strong>on</strong>. We therefore choose <strong>on</strong>e of these c<strong>on</strong>diti<strong>on</strong>s as a<br />
terminating c<strong>on</strong>diti<strong>on</strong> of the loop, and design the body of the loop in such a<br />
way that is preserves the truth of the other c<strong>on</strong>diti<strong>on</strong> (that is, the invariant<br />
of the loop); furthermore we ensure that the invariant is true before starting<br />
the loop.<br />
The obvious choice of invariant is exclusiveness (c<strong>on</strong>diti<strong>on</strong> (3)), leaving<br />
exhaustiveness as the terminating c<strong>on</strong>diti<strong>on</strong> towards which each executi<strong>on</strong><br />
of the body of the loop will progress. The empty timetable obviously satisfies<br />
the invariant. This leads to an algorithm of the following structure"<br />
timetable: = { };<br />
while timetable does not satisfy (2) do<br />
begin select a sessi<strong>on</strong> satisfying (4), (5), (6);<br />
end;<br />
add the sessi<strong>on</strong> to the timetable<br />
print timetable.<br />
In order for the additi<strong>on</strong> of a new sessi<strong>on</strong> to preserve the truth of the<br />
invariant, it is necessary that the exams of the sessi<strong>on</strong> shall be selected from<br />
exams which do not yet appear in the timetable. We therefore introduce a<br />
new variable to hold these remaining exams:<br />
remaining: powerset exam;<br />
which is defined by the invariant relati<strong>on</strong>"<br />
remaining = exam. all- ~ s.<br />
s in timetable<br />
The structure of the program as a whole now takes the form:<br />
timetable: = { };<br />
remaining" = exam. all;<br />
while remaining 4: { } do<br />
begin s'= suitable;<br />
end;<br />
print timetable.<br />
timetable: v {s };<br />
i<br />
remaining'- s