File and Data Organisation
FoundationA file consists of records, records consist of fields, and a key field uniquely identifies each record. Sequential files store records in key order and suit batch processing; random files locate records directly by key and suit instant response. Comparing search efficiency is the key to choosing an organisation.
- A file consists of records, records consist of fields, and the key field identifies each record uniquely
- Sequential files store records in key order; linear search averages half the records — good for batch processing
- Random files address records directly by key and hit in one access — good for instant response
文體小知識:科技知識說明文——講解檔案由記錄和欄組成的結構,順序檔與隨機檔的差異,以及線性檢索與直接存取的效率比較。
§Text Passage
1A file is a collection of related data, made up of records, each describing one object and composed of fields. In a library catalogue file, for example, each book is a record with fields such as title, author and call number. One field must be the key field whose value never repeats within the file, uniquely identifying each record — the call number here; duplicate key values would leave the system unsure which record to read or write.
2A sequential file stores records one after another in key order, and order must be maintained when new records are inserted. Reading scans from the beginning of the file until the target is found — this is a linear search. The larger the file, the slower the search: 1000 records need 500 comparisons on average, and 100000 records need 50000. Simple and cheap, sequential files suit periodic batch processing such as a monthly payroll.
3In a random file, a record's storage location is computed directly from its key by a formula, so the system reads or writes in one step by address — this is direct access. Whether the file holds a thousand or a hundred thousand records, a search usually takes one to a few accesses, far outperforming the sequential file. Random files suit systems needing instant response, such as ATM balance enquiries or live cinema ticketing, at the cost of more complex addressing and space management.
4Each organisation fits different situations. When data is always processed as a whole with no immediate response needed, sequential files are simple and cheap; when records must be queried or amended instantly by key, only random files are fast enough. In practice systems often use both: daily transactions accumulate in a transaction file, which is periodically merged into the master file holding long-term data — combining instant response with cost-effective batch processing.
1Summary 重點摘要
A file consists of records, records consist of fields, and a key field uniquely identifies each record. Sequential files store records in key order and suit batch processing; random files locate records directly by key and suit instant response. Comparing search efficiency is the key to choosing an organisation.
2Vocabulary cards Vocabulary
A collection of related records stored together under one name.
A set of related fields describing one object, such as one book in a catalogue file.
A single item of data within a record, such as a title or a phone number.
The field whose value is unique within the file and identifies each record.
The key that uniquely identifies each record, such as a student number or call number.
A file whose records are stored one after another in key order and read by scanning from the beginning.
A file whose record locations are computed from the key, allowing direct access.
A search that checks records one by one from the start until the target is found, averaging half the records.
Reaching a record immediately by computing its address from the key, without scanning other records.
The main file holding relatively permanent data, updated periodically by merging transaction records.
3Step by step Steps
- Step 1: Files, records and fieldsA file consists of records, and records consist of fields — the three levels must be kept clear. For example, in a school's student file each student is a record with fields such as student number, name, class and date of birth, and every record shares the same layout. Using the terms file, record and field accurately is basic technique; data questions often ask you to illustrate all three levels.
- Step 2: The role of the key fieldEvery file needs a key field whose value never repeats, uniquely identifying each record. For example, a school may have two students named Chan Tai Man, but their student numbers differ; a library uses the call number as key, a power company the customer number. Duplicate keys would leave the system unsure which record to read or write, so choosing a suitable unique key is the first step of file design.
- Step 3: How a sequential file worksA sequential file stores records in ascending key order, and reading scans from the beginning record by record — a linear search. For example, finding a student in 1000 records ordered by student number may hit on the first try or take 1000 comparisons — 500 on average. Inserting a record also shifts those after it. Sequential files win on simple structure and low cost, and lose on one-at-a-time search speed.
- Step 4: How a random file worksA random file converts the key into a storage address by a formula, and the system reads or writes at that address directly — direct access. For example, a cinema system computes the address from the session number plus seat number, so one access hits whether the house has a hundred or a thousand seats; a bank locates an account by account number, and balance queries need no waiting. The cost is more complex addressing and space management.
- Step 5: Comparing search efficiencyEfficiency is judged by how the number of comparisons grows with file size. Linear search grows in proportion to the records — 100000 records need 50000 comparisons on average; direct access usually takes one to a few accesses, nearly independent of file size. For example, a monthly payroll file is fine as a sequential file; an ATM answering in seconds must use a random file, or customers would queue.
- Step 6: Batch processing and master file updatesSequential files excel at batch processing: daily transactions accumulate in a transaction file, are sorted by key at month end, then merged with the master file to produce a new master file and reports. For example, a power company accumulates every household's electricity records over the month, then merges them with the customer master file to compute bills in one run of millions of records — highly efficient. Master file plus transaction file is the classic sequential pattern.
- Step 7: Criteria for choosing an organisationAsk three questions: does the data need instant response? how many records are processed each time? what are the storage and maintenance costs? For example, library loans need each catalogue record located at once, so a random file fits; a monthly citywide lending ranking is a batch job, so a sequential file suffices. In answers, state the scenario's needs first, match the file type, then justify with efficiency and cost.
5Worked example Example
A school library's catalogue file holds 40000 records sorted by call number and is currently stored as a sequential file. The library is considering switching to a random file. Compare the search efficiency of the two options and make a recommendation.
- Sequential efficiency: linear search averages half the records, 40000 ÷ 2 = 20000 comparisons, worst case 40000; at peak times every borrower queues at the counter.
- Random efficiency: the storage address is computed directly from the call number, so one access returns the record, almost unaffected by the 40000 records, with responses in milliseconds.
- Cost: a sequential file is simple and easy to maintain; switching requires reorganising 40000 records and handling address allocation, a higher upfront cost.
- Recommendation: loans and returns are instant queries, so efficiency first — switch to a random file; the monthly lending statistics report is a batch job and can keep the sequential routine.
- Answer: The sequential file searches 40000 records by linear search, averaging 40000 ÷ 2 = 20000 comparisons with a worst case of 40000 — too slow for instant response at peak times. A random file computes the address directly from the call number and answers in one access, far more efficient. Despite the reorganisation cost, borrowing must respond instantly, so a random file is recommended; the monthly statistics remain a batch job and can stay sequential. The decision balances response needs, processing mode and cost.
6Common mistakes Mistakes
7Quick check Quick check
Q1What is the relationship between file, record and field?
Q2Why are sequential files suitable for batch processing?
Q3How many comparisons does a linear search take on average in a 5000-record sequential file?
Q4How does a random file locate a record directly?
Q5Which file type should an ATM use for balance enquiries, and why?
8Recap Recap
- A file consists of records, records consist of fields, and the key field identifies each record uniquely
- Sequential files store records in key order; linear search averages half the records — good for batch processing
- Random files address records directly by key and hit in one access — good for instant response
- The master file holds long-term data and is periodically updated by merging the transaction file
- Choosing an organisation balances response needs, processing mode and cost