UNIHIVE

Study Hub UNIPORT CSC 283

CSC 283 · Information Systems and File Structures

Serial and sequential files

How serial and sequential files work, their uses, and how records are found, added and deleted.

Our notes

2 min read

Serial files

Records are written one after another in the order they occur, with no key order: a log of transactions as they happen, a CCTV event list, a file of the day's POS sales.

  • Adding a record: write it at the end (very fast).
  • Finding a record: read from the start until it turns up. On average half the file is read; if the record is not there, all of it.
  • Typical use: transaction files before sorting, audit logs, temporary files.

Sequential files

Records are stored in ascending (or descending) order of the primary key.

  • Ideal when most records are processed in key order (high hit rate): payroll, results computation, statement printing.
  • Two ordered files can be merged or matched in one pass.

Finding a record

  • On tape: read from the start until the key is found or a higher key is reached (then it is not there: the search can stop early because of the ordering).
  • On disk: binary search is possible because the records are in order and blocks can be read directly.

Worked example: search lengths

A sequential file of 10,000 records.

  • Linear search: on average about 10,000 ÷ 2 = 5,000 records read when the record is present.
  • Binary search on disk: at most ceiling(log₂ 10,001) = 14 probes, since 2¹⁴ = 16,384 is the first power of 2 above 10,000.

Adding and deleting

In a sequential file you cannot slot a record into the middle without moving everything after it. So changes are collected in a transaction file, sorted into the same key order, and applied in one pass that writes a new master file (next topic). Deletions are done by not copying the record to the new file.

Sorting

Transactions arrive in random order, so they are sorted first. Large files that do not fit in memory are sorted by external sorting: sort chunks in memory into ordered "runs", then merge the runs (a multiway merge), the method that made tape processing possible.

Merging two sequential files

Read the first record of each; repeatedly write the smaller key and read the next record from that file; when one file ends, copy the rest of the other.
Example: A = 3, 8, 15; B = 5, 8, 20 gives 3, 5, 8, 8, 15, 20 (equal keys: decide whether duplicates are allowed).

Advantages and disadvantages

AdvantagesDisadvantages
simple; little wasted spaceslow for single enquiries
very efficient at high hit ratesmust sort transactions first
works on cheap tapeinserting needs a new file
natural backup (old master kept)data out of date between runs

Exams usually ask

  • Distinguish serial and sequential files with uses.
  • Explain why a linear search on a sequential file can stop early.
  • Describe how a sequential file is merged or sorted.

Common mistake

Thinking records can be updated "in place" on tape. Tape cannot rewrite a record in the middle safely; a new master tape is always written.

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.

All CSC 283 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.