Information Technology Topic

Choosing File Organisation and Access

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. Choose by how the file is used. A whole-file run in key order, such as payroll, suits sequential organisation with sequential access. Quick look-ups of single records by key need direct access. A file that needs both suits index-sequential organisation
  2. Always name both choices, the organisation and the access method, and give a reason that mentions how the file is used. 'Faster' alone earns little
  3. Use the simple counts to justify a choice: a full pass of n records is n reads, a sequential search averages (n + 1) ÷ 2 reads, and an index look-up plus read is 2 steps. The index wins on enquiries and gives nothing on full runs

Section 1Two choices, one decision

Choosing for an application means picking two things: a file organisation (how the records are laid out) and an access method (how the program reaches them). The two must fit together. A plain sequential file allows only sequential access. Random and index-sequential files allow direct access too, and an index-sequential file also allows sequential access in key order. The skill is not memorising a list of applications. It is reading the scenario and asking how the file will be used.

Section 2The question to ask: how is the file used?

Pattern 1: the whole file, or most of it, is processed in one run, in key order. Choose sequential organisation with sequential access. Pattern 2: single records are needed quickly, one at a time, by key. Choose direct access, with a random or index-sequential organisation. Pattern 3: both patterns happen on the same file. Choose index-sequential: direct access for the look-ups and sequential access for the full runs. Here's the trick: look for the verbs in the scenario. 'Process every', 'print all' and 'each month for all' point to pattern 1. 'Look up', 'check', 'find one' and 'enquiry' point to pattern 2.

Section 3Payroll: sequential organisation, sequential access

Payroll is the example the syllabus names. Each pay period the program works out the pay for every employee, in employee-number order, and writes the pay slips. Every record is needed, in the same order, every time. So a payroll file is organised sequentially and accessed sequentially. Nothing is gained by jumping to records, because all of them are read anyway. The numbers: for 2,000 employees, one pass is 2,000 reads. Fetching each record through an index would take a look-up and a read each, 2 × 2,000 = 4,000 steps, double the work, plus an index to store and keep up to date. The same reasoning fits any job that handles the whole file in order, such as printing a report card for every student at the end of term.

Section 4Enquiries: direct access

An enquiry system answers 'what is the record for this key?' for one record at a time. A booking clerk checks a reservation by its booking number. A teller checks a balance by account number. A shop till finds a product by its product code. The key is a field that is different for every record, such as customer number, employee number or product code. These jobs need direct access, because reading through thousands of records one by one is too slow when someone is waiting at the counter. A random file or an index-sequential file gives it. The sums show why. In a file of 2,000 records a sequential search averages (2,000 + 1) ÷ 2 = 1,000.5 reads per enquiry. Through an index, in the simple model, it is 2 steps.

Section 5Both jobs: index-sequential

Many real files need both patterns. A credit union keeps account records. Tellers look up single accounts all day, and once a month a statement is printed for every account in account-number order. Index-sequential suits this: direct access by account number through the index for the tellers, and sequential access through the records in key order for the statement run. One file, two access methods. The cost is the index: extra storage, and keeping it in step whenever accounts are opened or closed. If a file never needed look-ups, that cost would buy nothing, which is why payroll stays sequential. Easy to mix up: index-sequential is not 'the best' organisation. It is the best when both patterns are needed.

Section 6Counting the cost

Use the same simple model every time. A sequential search averages (n + 1) ÷ 2 reads. A random read is 1 read. An index look-up plus a read is 2 steps. A full pass is n reads, and fetching every record one at a time through an index costs 2n steps. Worked: 12,000 account records. One enquiry by sequential search averages (12,000 + 1) ÷ 2 = 6,000.5 reads. 50 enquiries cost 50 × 6,000.5 = 300,025 reads. Through the index they cost 50 × 2 = 100 steps. A statement run for all 12,000 records is 12,000 reads in one sequential pass, but 24,000 steps if every record were fetched through the index. So the index wins big on enquiries and gives nothing on full runs. That is the whole argument.

Section 7Writing the answer

A good answer names both choices and ties them to the use. For example: 'Sequential organisation with sequential access, because every employee record is processed in one run in key order.' Or: 'Index-sequential organisation, with direct access for balance enquiries and sequential access for monthly statements.' Step 1: say how the file is used (a whole-file run, single look-ups, or both). Step 2: name the organisation. Step 3: name the access method, or both. Step 4: give the reason in terms of that use. If asked, step 5: name a cost. Watch out: do not write only 'it is faster' or 'it is easier'. Say faster for which job, and name the key field if it is a look-up, such as account number, product code or employee number.

Examples

At the end of term a school in Mandeville prints a report card for every one of its 640 students, in student-number order. (a) Choose a file organisation and an access method for the student file in this job. (b) Calculate how many reads are needed for the whole run with your choice, and how many steps it would take if each record were fetched through an index (one look-up plus one read each). (c) Explain why an index-sequential file is not needed for this job.

(a) Sequential organisation with sequential access. Every record is needed and in student-number order, so the whole file is processed in one run. (b) One pass reads each record once: 640 reads. Through an index each record costs a look-up and a read, 2 × 640 = 1,280 steps, which is 640 more steps than the sequential pass. (c) The job never needs to jump to a single student, so direct access would give nothing. The index would add storage and upkeep and double the work, with no benefit.

A credit union in Montego Bay keeps 12,000 account records, with account number as the key. Tellers look up the balance of one account at a time, about 50 times a day. At the end of each month a statement is printed for every account in account-number order. Use the simple model: an index look-up plus a read is 2 steps, and a sequential search for one account averages (n + 1) ÷ 2 reads. (a) Recommend an organisation and the access method for each of the two jobs. (b) Calculate the average reads for one enquiry in a plain sequential file, and the total for 50 enquiries, and compare with the index-sequential file. (c) Calculate the reads for the monthly statement run, and the steps if each record were fetched through the index. (d) State one cost of your recommendation.

(a) Index-sequential organisation for the file. Use direct access by account number for the balance enquiries, and sequential access through the records in key order for the statement run. One file does both jobs. (b) A plain sequential file averages (12,000 + 1) ÷ 2 = 6,000.5 reads per enquiry. For 50 enquiries: 50 × 6,000.5 = 300,025 reads. In the index-sequential file each enquiry is 2 steps, so 50 × 2 = 100 steps. (c) The statement run reads all 12,000 records once in key order: 12,000 reads. Fetching each through the index would cost 2 × 12,000 = 24,000 steps, so the statement run should use sequential access, not the index. (d) The index needs extra storage, and it must be updated whenever accounts are opened or closed, which makes writing slower.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from