Data Structures Notes
by
Farhan Sufyan
Contents
1 File Structure 1
1.1 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Types of Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Primary Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Secondary Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Chapter 1
File Structure
1.1 Indexing
• Indexing in data structures is a technique used to efficiently access and retrieve data from a database or a data
storage system. It involves creating a data structure that facilitates fast lookup and access to specific data
records.
1.1.1 Types of Indexing
There are two main types of indices:
1. Primary Index
2. Secondary Index
1
1.2 Primary Index
• A primary index is a unique identifier for each record in a database table.
• It is typically a unique key that distinguishes each record from others.
• A primary index is usually created on a column that has unique values, such as an ID or a social security
number.
• Example:
– Suppose we have a database table called "Employees" with the following columns: Employee ID,
Name, Department, and Salary.
– The Employee ID column can be used as a primary index because it has unique values for each
employee.
1.3 Secondary Index
• A secondary index is a data structure that facilitates fast access to records based on a column other than the
primary index.
• Secondary indices are created on columns that are frequently used in search queries.
• Example: In the "Employees" table, we can create a secondary index on the Department column. This
allows for fast retrieval of all employees in a specific department.
1.4 Example
Employee ID (Primary Index) Name Department (Secondary Index) Salary
101 John Smith Sales 50000
102 Jane Doe Marketing 60000
103 Bob Johnson Sales 55000
104 Maria Rodriguez Marketing 65000
In this example, the Employee ID column is the primary index, and the Department column is a secondary
index. The secondary index on the Department column allows for fast lookup of all employees in the Sales or
Marketing departments.