Computer Science  ·  Level 6
Database Management
Chapter 5: Indexing and hashing
📚 4 Topics
⚑ What you will be able to do

By the end of this chapter, you will be able to:

  • apply indexing techniques correctly to improve how fast a database works
  • use hashing methods safely and effectively to organize data
  • create accurate indexes in databases to speed up data searches
  • implement indexing and hashing in an existing database by following the right steps

Mastering these skills will help you make databases run smoothly and efficiently, which is essential in any data-driven job.

Indexing and hashing are fundamental techniques in database management that significantly enhance the efficiency of data retrieval operations. In Kenya's dynamic technology landscape, where applications such as mobile banking, e-government services, and health information systems generate vast datasets, effective indexing and hashing enable swift access to critical information. Professionals working in software development firms, financial institutions like Equity Bank, and county government IT departments rely on these methods to optimize query performance and ensure scalable system responsiveness. This chapter explores the concepts, types, and practical applications of indexing and hashing within relational databases.

5.1 Indexing and Hashing

Indexing and hashing are complementary strategies used to accelerate data lookup in databases. While indexing organizes data references to facilitate quick searches, hashing transforms keys into unique addresses for direct access. Understanding their definitions, varieties, and mechanisms equips computer science professionals with tools to design high-performance databases tailored to Kenyan contexts such as national revenue systems and healthcare record management.

5.1.1 Definition of Indexing and Hashing

Indexing and hashing serve as core methods to reduce the time complexity of searching data in large databases. These techniques are essential in scenarios like managing customer records at SACCOs or inventory databases in retail chains.

Definition of Indexing

Indexing is a database optimization technique that creates a data structure, typically a separate file or a tree, referencing specific database records based on key values. This structure enables the database management system (DBMS) to locate data without scanning entire tables, thus improving query speed. For instance, a university’s student database uses indexes on student ID numbers to quickly retrieve academic records without full table scans.

Definition of Hashing

Hashing involves applying a hash function to a search key to compute a hash value that directly corresponds to a location where the data is stored. This method supports constant-time data retrieval in ideal conditions. In practice, hashing is used in applications like mobile money platforms where rapid validation of transaction IDs is critical.

Differences Between Indexing and Hashing

  • Indexing maintains an ordered structure of keys and pointers, enabling range queries and sorted data access, whereas hashing provides direct access but does not preserve order.
  • Indexes can support multiple types of queries including range and wildcard searches; hashing is efficient primarily for exact-match queries.
  • Indexing structures such as B-trees consume more space and require maintenance during data updates; hashing often requires less storage but may suffer from collisions.
  • Indexing is more suitable for databases with frequent range queries, such as time-series data in environmental monitoring; hashing excels in applications requiring fast, unique key lookups like user authentication systems.
  • Both techniques trade off between speed, storage overhead, and complexity based on the database workload.

Importance in Kenyan Database Systems

In Kenyan financial institutions, indexing accelerates customer data retrieval for loan processing, while hashing secures and expedites password verification in online banking portals. These methods ensure responsive and reliable services critical to user satisfaction.

5.1.2 Types of Indexing

Indexing comes in several forms, each designed to optimize access patterns depending on the nature of data and query types. Kenyan software developers must choose appropriate indexes to balance query speed and storage overhead in systems like hospital patient management and county tax registries.

Primary Indexing

A primary index is created on a database’s primary key, which uniquely identifies each record. It organizes data in sorted order based on the key values, facilitating efficient direct access. For example, the National Hospital Insurance Fund (NHIF) uses primary indexes on membership numbers to retrieve subscriber information rapidly.

Secondary Indexing

Secondary indexes are built on non-primary key attributes to support queries that filter or sort by other columns. In a university database, a secondary index on course codes allows quick retrieval of all students enrolled in a particular course, even though course code is not the primary key.

Clustered Indexing

Clustered indexes reorder the physical storage of data to match the index order, enhancing performance for range queries. In a retail inventory system, clustering product records by category enables efficient stock level reports per category.

Non-Clustered Indexing

Non-clustered indexes maintain a separate structure without altering the physical order of data. This is useful in banking systems where multiple indexes on attributes like account type and branch code enable diverse query capabilities without restructuring tables.

Composite Indexing

Composite indexes involve multiple columns combined as a single key to optimize queries filtering on several attributes simultaneously. For example, a county government database may use a composite index on ward and property type to expedite property tax assessments.

5.1.3 Types of Hashing

Hashing techniques vary based on how the hash function is designed and how collisions are resolved. Kenyan database engineers must select hashing methods that balance speed and collision handling for applications ranging from mobile payment systems to agricultural data platforms.

Static Hashing

Static hashing uses a fixed-size hash table where the hash function maps keys to a predetermined number of buckets. It is simple but can suffer performance degradation if data volume exceeds capacity, causing collisions. Static hashing might be used in small-scale cooperative banking systems with stable client numbers.

Dynamic Hashing

Dynamic hashing adjusts the hash table size dynamically as data grows, reducing collision probability and maintaining performance. This method suits scalable applications like national identification databases that experience continuous data growth.

Linear Hashing

Linear hashing incrementally expands the hash table by splitting buckets one at a time, allowing smooth growth without the need for complete rehashing. It is effective in government tax databases where records increase steadily over time.

Extendible Hashing

Extendible hashing uses a directory of pointers and allows the hash table to expand by doubling the directory size, managing collisions efficiently. It is appropriate for large-scale online platforms, such as e-commerce systems, requiring rapid and scalable access.

Cuckoo Hashing

Cuckoo hashing employs multiple hash functions and relocates existing keys to resolve collisions, ensuring constant worst-case lookup time. Innovations like this can be applied in critical systems such as Kenya Revenue Authority’s real-time transaction verification.

Practice Questions

  1. Define indexing and hashing, highlighting their key differences in database management. (10 marks)
  2. Explain the advantages of clustered indexing over non-clustered indexing with examples from Kenyan institutions. (10 marks)
  3. Describe dynamic hashing and discuss why it might be preferred over static hashing in national ID databases. (10 marks)
  4. List and explain four types of indexing and their typical use cases in Kenyan public sector databases. (20 marks)
  5. Discuss the challenges of collision resolution in hashing and how extendible hashing addresses these challenges. (10 marks)
The rest of this chapter
🔒

Create a free account to open more of this chapter.

Free: practical guides, quick cards, workplace scenarios and more.

Create a free account
🔒5.2 Demonstration of indexing

Indexing is a fundamental technique in database management that significantly enhances data retrieval speed. For computer science professionals working with large databases in Kenya, such as in banking systems like KCB or mobile money platforms, efficient inde…

🔒5.3 Demonstration of hashing

Hashing is another indexing technique that uses a hash function to compute the address of the data record. This method is particularly useful in situations requiring rapid equality searches, such as retrieving customer profiles by account number in Kenyan bank…

🔒5.4 Implementation of indexing and hashing in an existing database

In Kenyan Computer Science environments, especially within enterprises handling large datasets such as banks, universities, and government agencies, efficient data retrieval is critical. Implementing indexing and hashing in existing databases improves query pe…

Chapter Summary

This chapter explored the concepts of indexing and hashing as fundamental techniques for efficient data retrieval in database management. It began with definitions clarifying how indexing organizes data to speed up search operations, while hashing uses hash functions to map data to specific locations. Various types of indexing were examined, including primary, secondary, and multilevel indexes, highlighting their distinct structures and use cases. The chapter then detailed types of hashing, focusing on static and dynamic hashing methods that differ in flexibility and handling of data growth. Demonstrations of indexing covered dense and sparse index implementations, explaining how each affects storage and access speed. Similarly, demonstrations of hashing elaborated on static hashing’s fixed structure and dynamic hashing’s adaptability. Finally, the chapter discussed practical considerations for implementing indexing and hashing within existing database systems, emphasizing their role in optimizing query performance and data management.

Self-Assessment

🔒 PDFDownload this self-assessment, with answers

A. Written Assessment

  1. Define indexing and explain its main purpose in database management. (3 marks)
  2. What is hashing and how does it differ from indexing in terms of data retrieval? (3 marks)
🔒20 more in this section.

Chapter Examination Questions

🔒 PDFDownload these examination questions, with worked answers

SECTION A (40 Marks) - Answer ALL Questions

  1. Explain the difference between indexing and hashing in database management, using an example relevant to a Kenyan financial institution such as Equity Bank. (4 marks)
  2. Describe the main characteristics of a dense index and explain when it would be preferable over a sparse index. (4 marks)
🔒18 more in this section.

Chapter Practical Activities

Practical 1: Explain and Demonstrate Indexing and Hashing Concepts

Computer Science · Level 6
Database Management
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)

Type: Individual

INSTRUCTIONS TO CANDIDATE:
1.  You are required to perform the following task:
i.  Create a sample database named 'BankDB' with a table 'CustomerAccounts' containing 5 fields and demonstrate indexing on the AccountNumber field and hashing on the CustomerID field.
2.  You have been provided with the following resources for the practical task:
Tools & EquipmentMaterials
Functional computer with MS SQL Server installedPlain A4 paper
⬇ PDFResources Required (Cutting List)
S/NItemQuantity
1Functional computer with MS SQL Server installed1 Pc per Candidate
2Plain A4 paper2 Sheets per Candidate
⬇ PDFAssessor Guide
Items to be EvaluatedMarks AvailableMarks ObtainedComments
TASK 1: Create database and table structure
Observed computer laboratory rules
(Award 2 marks or zero)
2
Launched MS SQL Server correctly
(Award 2 marks or zero)
2
Created database 'BankDB' successfully
(Award 3 marks or zero)
3
Created table 'CustomerAccounts' with correct fields and data types (CustomerID, AccountNumber, AccountName, AccountType, Balance)
(Award 5 marks or zero)
5
Sub-Total12
TASK 2: Insert sample records
Inserted at least 10 sample records into 'CustomerAccounts' table
(Award 4 marks or zero)
4
Sub-Total4
TASK 3: Demonstrate indexing and hashing
Created an index on the AccountNumber field
(Award 5 marks or zero)
5
Explained the concept of indexing verbally or in writing
(Award 3 marks or zero)
3
Demonstrated hashing concept by creating a hash function or explained hashing with an example using CustomerID
(Award 6 marks or zero)
6
Explained the benefits of indexing and hashing in database management
(Award 4 marks or zero)
4
Sub-Total18
PRODUCT CHECKLIST
Database 'BankDB' with 'CustomerAccounts' table created correctly with accurate fields and data types
(Award 5 marks or zero)
5
Sample records correctly inserted and visible in the table
(Award 5 marks or zero)
5
Index created on AccountNumber field verified through SQL Server Management Studio or query
(Award 5 marks or zero)
5
Hashing concept demonstrated with clear example or hash function applied and explained
(Award 5 marks or zero)
5
Sub-Total20
GRAND TOTAL54
ASSESSMENT OUTCOME:   ☐ Competent    ☐ Not Yet Competent (competent if at least 50%)

Practical 2: Identify and Describe Types of Indexing in Databases

Computer Science · Level 6
Database Management
PRACTICAL ASSESSMENT
TIME: 4 HOURS
⬇ PDFCandidate Instructions (Candidate Tool)

Type: Individual

INSTRUCTIONS TO CANDIDATE:
1.  You are required to perform the following task:
i.  List and describe five types of database indexing and explain their typical use cases in a one A4 page report.
2.  You have been provided with the following resources for the practical task:
Tools & EquipmentMaterials
Functional computer installedPlain paper
Pen
⬇ PDFResources Required (Cutting List)
S/NItemQuantity
1Functional computer installed1 Pc per Candidate
2Plain paper2 Sheets per Candidate
3Pen1 Pc per Candidate
⬇ PDFAssessor Guide
Items to be EvaluatedMarks AvailableMarks ObtainedComments
TASK 1: Identification and Description of Indexing Types
Observed computer laboratory rules
(Award 2 marks or zero)
2
Listed at least five distinct types of indexing (e.g. Primary, Secondary, Clustered, Non-clustered, Hash Index)
(Award 1 mark for each correct type listed, 5 marks max)
5
Provided clear and accurate description of each indexing type
(Award up to 2 marks per description based on clarity and accuracy)
10
Explained typical use cases or scenarios for each type of indexing
(Award up to 1.6 marks per use case explanation)
8
Sub-Total25
PRODUCT CHECKLIST
Report is well-structured, legible, and contains all required information as per task instruction
(Award 5 marks for completeness, clarity, and presentation)
5
Sub-Total5
GRAND TOTAL30
ASSESSMENT OUTCOME:   ☐ Competent    ☐ Not Yet Competent (competent if at least 50%)
🔒

Free: practical guides, quick cards, workplace scenarios and more.

Create a free account
🔒Identify and Describe Types of Hashing Methods in Database SystemsPractical 3
🔒Create and Demonstrate a Dense Index on Student RecordsPractical 4
🔒Create and Demonstrate a Sparse Index on a Student Records DatabasePractical 5
🔒Implement and Demonstrate Static Hashing on a Student DatabasePractical 6
🔒Implementation and Demonstration of Dynamic Hashing on a Student DatabasePractical 7
🔒Compare Dense and Sparse Indexing Methods on Student RecordsPractical 8
🔒Implementation and Comparison of Static and Dynamic Hashing MethodsPractical 9
🔒Apply indexing to the Customer Orders database to improve query performancePractical 10
🔒Apply hashing technique to optimize data access in a student databasePractical 11
Flashcards 20 cards Study deck ▾
Question
1

↻ Tap card to reveal answer
🔒

18 more in this section.

Create a free account
Test Yourself 18 questions Start quiz ▾
0%
0 / 2
🔒

16 more in this section.

Create a free account
Am I competent?

At the start of this chapter we promised you would be able to:

  • apply indexing techniques correctly to improve how fast a database works
  • use hashing methods safely and effectively to organize data
  • create accurate indexes in databases to speed up data searches
  • implement indexing and hashing in an existing database by following the right steps

Tick each one you can genuinely do.

So, are you there yet?

You're competent when you can confidently do 50% or more of what this chapter promised.

Sign in to record how you're doing.