Access Methods
Access Methods
When data is stored in files, applications need to access it in various ways based on
how the data is structured and what the application needs. "Access methods" refer
to these different ways of reading, writing, or navigating data within a file. Each
method serves specific needs, balancing between speed, flexibility, and simplicity.
Let’s explore the main access methods: **Sequential Access**, **Direct Access**,
and **Indexed Access**.
---
#### Definition
Sequential access is the simplest and most common access method. Data is
processed in a specific, ordered sequence—from the beginning of the file to the end.
Think of a playlist where songs play one after the other without skipping.
#### Example
Imagine reading a novel page by page. If you want to read a specific scene, you still
have to start from the beginning and read until you reach it.
---
#### Definition
Direct access (also called "random access") allows reading or writing data in any
order, making it possible to "jump" to specific parts of the file. This method is based
on a numbered structure, where data is stored in fixed-size blocks or records.
#### Example
Imagine a bookshelf full of encyclopedias. If you need information on "polar bears,"
you don’t start at the beginning of the book. You go directly to the "P" section.
---
#### Definition
Indexed access builds on direct access by adding an "index," which points to
specific data blocks or records. An index acts like a table of contents or a book
index, where you find the topic and go directly to its location in the file.
#### How It Works
1. **Create Index**: The index stores the first entry for each block, along with
pointers to where each block is stored.
2. **Search Index**: To find a specific record, we first search the index, locate the
relevant block, and then access that block directly.
#### Example
In a library database, each book’s unique ID is listed in an index with a pointer to
where the book’s details are stored. When you look up a book by its ID, you go to
the exact location without scanning through all records.
---
Each access method has strengths suited to different tasks, so understanding these
can help choose the most efficient way to store and retrieve data in real-world
applications.