
Hash tables are widely used to store and retrieve data efficiently. However, hash collisions are unavoidable.
In this assignment, you will implement a traditional hash table using separate chaining with linked lists to handle collisions.
You are not allowed to use Python built-in dictionaries (dict) or any hash table libraries.

| Attribute | Type | Description |
|---|---|---|
| key | string | Key used for hashing |
| value | any | Value associated with the key |
| next | Node | Reference to the next node in the bucket |
| Component | Type | Description |
|---|---|---|
| table | list | Array of linked lists (buckets) |
| size | int | Number of buckets |
| count | int | Number of stored key–value pairs |
| Function | Description |
|---|---|
hash_function(key) |
Compute hash index from key |
insert(key, value) |
Insert or update a key–value pair |
search(key) |
Retrieve value by key |
delete(key) |
Remove key–value pair |
display() |
Show full hash table structure |
load_factor() |
Return current load factor |
Convert a key into an index of the hash table.
Work in:
Input
| Parameter | Type | Description |
|---|---|---|
| key | string | Key to be hashed |
Output
| Type | Description |
|---|---|
| int | Index in range [0, table_size - 1] |
Ex:
1
hash_function("apple") => 3
Insert a new key–value pair into the hash table or update an existing key.
Work in:
Input
| Parameter | Type | Description |
|---|---|---|
| key | string | Key to insert |
| value | any | Value associated with the key |
Output
| Type | Description |
|---|---|
| None | Prints insertion/update message |
Ex:
1
2
Key 'apple' inserted at index 3
Key 'apple' updated at index 3
Retrieve the value associated with a given key.
Work in:
Input
| Parameter | Type | Description |
|---|---|---|
| key | string | Key to search |
Output
| Type | Description |
|---|---|
| any | Value associated with the key |
| None | If key is not found |
Ex:
1
2
Value for key 'banana': 20
Key 'orange' not found
Remove a key–value pair from the hash table.
Work in:
Input
| Parameter | Type | Description |
|---|---|---|
| key | string | Key to remove |
Output
| Type | Description |
|---|---|
| bool | True if deletion successful, False otherwise |
Ex:
1
2
Key 'banana' removed from index 1
Key 'orange' not found
Show the full internal structure of the hash table.
Work in:
Output
Printed representation of the hash table.
Ex:
1
2
3
4
5
Hash Table:
[0] -> apple:10 -> mango:5
[1] -> banana:20
[2] -> empty
[3] -> grape:7
Measure how full the hash table is.
Work in:
Output
| Type | Description |
|---|---|
| float | Current load factor |
Ex:
1
Load factor: 0.6
Universities need to store and retrieve student records efficiently. Searching student information using linear data structures becomes slow when the number of students increases.
In this assignment, you will design a Student Record Management System using a Hash Table implemented with linked lists to handle collisions.
This system will allow fast insert, search, and delete operations based on a student ID.
You are not allowed to use Python built-in dictionaries or hash table libraries.
| Attribute | Type | Description |
|---|---|---|
| student_id | string | Unique student identifier |
| name | string | Student full name |
| major | string | Student major |
| next | Node | Pointer to next node in bucket |
| Function | Description |
|---|---|
hash_function(student_id) |
Compute bucket index |
add_student(id, name, major) |
Insert or update student |
find_student(id) |
Retrieve student record |
remove_student(id) |
Delete student record |
display_all() |
Show entire hash table |
load_factor() |
Calculate load factor |
The program processes user commands from standard input.
Add or Update Student
1
ADD <student_id> <name> <major>
Ex:
1
ADD S123 Alice ComputerScience
Output:
1
Student S123 added at index 2
or
1
Student S123 updated at index 2
1
FIND <student_id>
Output:
1
2
3
4
Student Found:
ID: S123
Name: Alice
Major: ComputerScience
or
1
Student S999 not found
1
REMOVE <student_id>
Output:
1
Student S123 removed from index 2
or
1
Student S999 not found
1
DISPLAY
Output:
1
2
3
4
5
Hash Table:
[0] -> S101 -> S202
[1] -> empty
[2] -> S123 -> S305
[3] -> S450
1
EXIT
Many real-world applications rely on string keys, such as usernames, URLs, email addresses, and dictionary words.
In this assignment, you will implement a hash table that uses string-based hash functions to efficiently store and retrieve words and their definitions.
Collisions must be handled using separate chaining with linked lists.
You are not allowed to use Python built-in dictionaries or hashing utilities.
| Attribute | Type | Description |
|---|---|---|
| word | string | Dictionary word (key) |
| meaning | string | Definition of the word |
| next | Node | Pointer to next node in bucket |
| Component | Description | |
|---|---|---|
| table | List | Array of linked lists |
| size | int | Number of buckets |
| count | int | Number of stored words |
| Function | Description |
|---|---|
hash_function(word) |
Compute hash index from string |
insert(word, meaning) |
Add or update word |
search(word) |
Find word definition |
delete(word) |
Remove word |
display() |
Show full hash table |
collision_count() |
Return number of collisions |
Hash Formula:
1
2
3
hash = 0
for each character c in word:
hash = (hash * 31 + ASCII(c)) % table_size
- 31 is a commonly used prime number
- ASCII(c) is the ASCII value of character c
The program reads commands from standard input.
Add or Update Student
1
ADD ADD <word> <meaning>
Ex:
1
ADD algorithm "a step-by-step procedure"
Output:
1
Word 'algorithm' inserted at index 4
or
1
Word 'algorithm' updated at index 4
1
FIND <word>
Output:
1
Meaning of 'algorithm': a step-by-step procedure
or
1
Word 'algorithm' not found
1
REMOVE <word>
Output:
1
Word 'algorithm' removed from index 4
or
1
Word 'algorithm' not found
1
DISPLAY
Output:
1
2
3
4
5
6
7
Hash Table:
Hash Table:
[0] -> empty
[1] -> data["..."] -> structure["..."]
[2] -> empty
[3] -> queue["..."]
[4] -> algorithm["a step-by-step procedure"] -> array["a list"]
1
EXIT