File Organisation, File Access
& Hashing
FILE ORGANISATION METHODS
File organisation = how records are physically arranged in a file.
There are 3 main methods:
Serial File Organisation
Definition
Records are stored in the file in the order they arrive (no sorting).
Example
Imagine recording customers as they come:
Order added
Record
1
Customer A
2
Customer D
3
Customer B
Records may not be sorted by ID.
Uses
●
●
●
Small files
Temporary files
Simple tasks (e.g., queue of daily transactions)
Advantages
●
●
Very simple to create
Records just get added at the end
Disadvantages
●
Searching is slow (must check every record)
Sequential File Organisation
Definition
Records are stored in order of a key field (e.g., sorted by customer ID).
Example
If sorted by Customer ID:
ID
Record
1
Customer 1
2
Customer 2
3
Customer 3
New records are inserted in the correct position, not at the end.
Uses
●
●
●
Payroll systems
Billing systems
Monthly bank statements
(Where almost every record must be processed)
Advantages
●
●
Faster searching than serial (sorted order)
Good for reports where all records are needed
Disadvantages
●
●
Inserting a new record requires rewriting the file
Not suitable for rapid updates
Random (Direct) File Organisation
Definition
Records are stored anywhere in the file using a hashing algorithm to calculate their location.
Example
If the hashing algorithm gives index 20, then:
Record with key 1023 → stored at location 20
Uses
●
●
●
Very fast access needed
Large databases
Customer‑ lookup systems
Advantages
●
●
Very fast (direct access)
No need to search entire file
Disadvantages
●
●
Collisions may happen (two records hashing to same location)
Needs hashing algorithm + overflow management
METHODS OF FILE ACCESS
File access = how records are retrieved from a file.
There are two main types:
Sequential Access
Definition
Records are read one after another, from the start of the file until the required record is found.
Example
If looking for Customer 7:
Read Customer 1 → not match
Read Customer 2 → not match
...
Read Customer 6 → not match
Read Customer 7 → FOUND
Uses
●
●
●
●
Serial files
Sequential files
Bank statements
Payroll processing
Advantages
●
●
Simple
Good when all records must be processed
Disadvantages
●
●
Very slow if the record is at the end
Not suitable for large files
Direct Access (Random Access)
Definition
The computer uses an arithmetic calculation (hashing) or an index to jump directly to a record
without reading others.
Example
Searching for customer with ID 5024:
address = key MOD 2000
= 5024 MOD 2000
= 1024
So record is stored at location 1024.
Uses
●
●
●
Databases
Large customer systems
Password files
Advantages
●
●
Very fast
Only the needed record is read
Disadvantages
●
●
Requires hashing/index tables
Collisions must be managed
HASHING ALGORITHMS
A hashing algorithm performs a mathematical calculation on a key (e.g., customer ID) to determine
where the record will be stored.
How Hashing Works
Example:
File can store 2000 records
Key field values: 1–9999
Hash function:
Address = key MOD 2000
✅ Example Calculation
Store key: 3024
3024 MOD 2000 = 1024
Address = 1024
So record is stored at location 1024.
Collision
A collision happens when two different keys produce the same address.
Example:
3024 MOD 2000 = 1024
5024 MOD 2000 = 1024
Both want to go to 1024 → collision.
How to Handle Collisions
Two common solutions:
1. Open Hashing (Linear Probing)
If the calculated location is used → store in the next free space.
Example:
●
●
Address 1024 is full
Check 1025
●
If 1025 free → store there
2. Closed Hashing (Overflow Area)
A separate "overflow" area is used.
If 1024 is full → send record to overflow file.
Hashing in Direct Access File
To read a record:
1. Apply hashing algorithm to key
2. Jump to calculated address
3. Check if key matches
4. If not → follow collision-handling method until found
✅ SUMMARY TABLE
Topic
Meaning
Best For
Weakness
Serial Organisation
Records stored in arrival order
Simple logs,
temporary files
Slow searching
Sequential
Organisation
Records sorted by key
Payroll, billing
Hard to insert
Random
Organisation
Records placed using hashing
Fast access,
databases
Collisions
Sequential Access
Read from start to target
Full file processing
Slow for single
record
Direct Access
Jump straight to record using
hashing/index
Databases,
password files
Needs extra
structures
Hashing Algorithm
Calculates storage address
Very fast lookups
Collisions
possible