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.

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

11.2. DATA REPRESENTATION<br />

In order to design a successful data representati<strong>on</strong>, it is necessary to know<br />

something of the likely size of the problem. In this example, we will make the<br />

following assumpti<strong>on</strong>s:<br />

(1) There are not more than 500 exams, each taken by less than 1000<br />

students (typically 50).<br />

(2) There are about 5000 students.<br />

(3) Each student takes less than ten exams, and typically five.<br />

(4) The examinati<strong>on</strong> hall will take about 1000 students.<br />

(5) An acceptable limit <strong>on</strong> the number of c<strong>on</strong>current exams is 30, and the<br />

typical number is 10.<br />

(6) Manual timetabling methods have succeeded in c<strong>on</strong>structing timetables<br />

with not more than 50 sessi<strong>on</strong>s.<br />

We will c<strong>on</strong>sider the individual items of data.<br />

(1) type exam<br />

The obvious representati<strong>on</strong> is as an integer subrange:0.. 500.<br />

(2) type sessi<strong>on</strong><br />

There is obviously a choice between a bitpattern representati<strong>on</strong> (500 bits),<br />

and an array of 30 nine-bit elements (+ pointer) (270 bits + <strong>on</strong>e word). The<br />

number of sessi<strong>on</strong>s to be stored is not great, so c<strong>on</strong>siderati<strong>on</strong>s of storage<br />

ec<strong>on</strong>omy are not significant. The main operati<strong>on</strong>s <strong>on</strong> the sessi<strong>on</strong> are the<br />

inserti<strong>on</strong> of an exam which is known not to be in it already, and the removal<br />

of an exam, which is the most recently inserted. Thus the array method<br />

would be the best, since the inserti<strong>on</strong> and removal of members can be<br />

accomplished by stack methods.<br />

Since we frequently wish to know the sessi<strong>on</strong>-count, it would pay to record<br />

this together with the sessi<strong>on</strong>, and keep it up to date as members are inserted<br />

and removed.<br />

This representati<strong>on</strong> is used for trial and bestsofar.<br />

(3) t#netable<br />

The <strong>on</strong>ly operati<strong>on</strong> <strong>on</strong> the timetable is the inserti<strong>on</strong> of new sessi<strong>on</strong>s. Since<br />

sessi<strong>on</strong>s are of variable length, the timetable could be organised as a sequence<br />

of variable-length sequences. Since each exam occurs exactly <strong>on</strong>ce in the<br />

timetable, the maximum size of the timetable is 500 x nine bits, plus perhaps<br />

sixty words to indicate the separati<strong>on</strong> of the sessi<strong>on</strong>s (if there are more than<br />

sixty sessi<strong>on</strong>s, the program will have failed anyway).

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

Saved successfully!

Ooh no, something went wrong!