Hashing (Cambridge (CIE) A Level Computer Science): Revision Note

Exam code: 9618

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Hashing algorithms

What is a hashing algorithm?

  • A hashing algorithm is used to calculate the storage location (address) of a record in a random (direct access) file

  • It allows for fast access to data without searching sequentially through a file

Why use hashing?

  • Provides direct access to records using a key (e.g. ID, account number)

  • Useful when dealing with large files that need fast search, read, or write operations

  • Used in random files and sometimes in indexed sequential files

How hashing works?

  • A hashing algorithm takes a key (e.g. StudentID) and uses a mathematical function to calculate a file address

Address = HashFunction(Key)
  • If two keys produce the same address, a collision occurs

  • This must be resolved (e.g. via linear probing or overflow areas)

Writing a record to a file:

Address ← HashFunction(Key)
WRITE file[Address], Record

Reading a record from a file:

Address ← HashFunction(Key)
READ file[Address], Record
  • If the expected record is not found, collision handling must be applied to find the correct record

Types of hashing algorithms

Method

Description

Modulo Division

Most common method: Key MOD TableSize

Folding Method

Breaks the key into parts and adds them together

Mid-Square Method

Square the key and use the middle digits as the address

Multiplicative Hashing

Multiplies the key by a constant and uses fractional part × tablesize

Collision handling strategies

Strategy

Description

Linear probing

Try the next available slot in sequence

Overflow area

Store conflicting records in a separate file/area

Chaining

Store all records with the same address in a list

You've read 0 of your 5 free revision notes this week

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.