II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
162 C. A. R. HOARE<br />
hallsize, k'integer, initially given;<br />
load:array student of powerset exam, initially given;<br />
type sessi<strong>on</strong> = powerset exam;<br />
timetable:powerset sessi<strong>on</strong>, initially { };<br />
examcount: array exam of integer, initially all (0);<br />
incompat:array exam of powerset exam, initially c<strong>on</strong>stant ( { } );<br />
functi<strong>on</strong> sessi<strong>on</strong>count (s: sessi<strong>on</strong>): integer;<br />
begin sum: integer, initially 0;<br />
end;<br />
for e in s do sum: + examcount (e);<br />
sessi<strong>on</strong>count: -- sum<br />
remainin/~: powerset exam, initially exam. all;<br />
functi<strong>on</strong> suitable: sessi<strong>on</strong>;<br />
begin bestsofar, trial: sessi<strong>on</strong>; untried: powerset exam;<br />
end;<br />
e: exam; e from remainder; bestsofar: = {e };<br />
trial: = {e}; untried: = remainder - trial - incompat (e);<br />
gensupersets;<br />
suitable: = bestsofar<br />
The following two procedures are local to suitable:<br />
procedure record;<br />
if sessi<strong>on</strong>count (bestsofar) < sessi<strong>on</strong>count (trial) then<br />
bestsofar: = trial;<br />
procedure gensupersets;<br />
begin e" exam; save 1, save 2"powerset exam;<br />
record; save 1 : = untried;<br />
if size (trial) < k then<br />
while untried ~ { } do<br />
begin e from untried;<br />
save 2: = untried A incompat (e);<br />
untried" - save;<br />
trial: v {e};<br />
if sessi<strong>on</strong>count (trial) < hallsize then<br />
gensupersets;