CSC 283 · Information Systems and File Structures
Our notes
2 min readThe files
- Master file: the main, fairly permanent file (student records, account balances), in key order.
- Transaction file: the changes for this run (new registrations, payments, withdrawals), each with a key and a code: I (insert), A (amend), D (delete).
- New master file: written by the run.
- Error report: transactions that could not be applied.
The steps
- Validate transactions (correct format, valid codes, sensible values).
- Sort them into master key order.
- Match master and transaction records in one pass (the balance-line or match-merge method).
The matching logic
Read one master (M) and one transaction (T). Then repeat:
- If M.key < T.key: no change for this master: copy M to the new master; read the next M.
- If M.key = T.key:
- A: apply the change to M (keep it in memory; more amendments may follow); read next T.
- D: drop M (do not copy it); read next M and next T.
- I: error (record already exists); read next T.
- If M.key > T.key:
- I: write the new record to the new master; read next T.
- A or D: error (no such record); read next T.
Use a "high value" key (larger than any real key) at the end of each file so the loop finishes cleanly.
Worked example
Master keys: 101, 104, 107, 110.
Transactions (sorted): 102 I, 104 A, 107 D, 108 A, 110 A, 112 I.
| Step | M | T | Action |
|---|---|---|---|
| 1 | 101 | 102 I | 101 < 102: copy 101 |
| 2 | 104 | 102 I | 104 > 102, insert: write 102 |
| 3 | 104 | 104 A | equal, amend 104 |
| 4 | 104 | 107 D | 104 < 107: copy amended 104 |
| 5 | 107 | 107 D | equal, delete: skip 107 |
| 6 | 110 | 108 A | 110 > 108, amend: error "108 not found" |
| 7 | 110 | 110 A | equal, amend 110 |
| 8 | 110 | 112 I | 110 < 112: copy amended 110 |
| 9 | end | 112 I | insert: write 112 |
New master: 101, 102, 104 (amended), 110 (amended), 112. Error report: 108.
Why the old master is kept
The run never changes the old master, so if anything goes wrong the run can be repeated from the old master and the transactions. This is the basis of the grandfather-father-son backup system (see file maintenance).
Exams usually ask
- Describe the files used in a sequential update and the role of each.
- Write or trace the matching algorithm for given master and transaction keys.
- List the errors that the update must report.
Common mistake
Writing the master record as soon as one amendment is applied. Several amendments for the same key may follow; write the record only when the next transaction key is higher.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
No reading links here yet
Our team adds free books, videos and practice for each topic, and opens every link before it goes up.