Indexed Sequential Search in Data Structure: Algorithm & Example
First read a tiny index, then search only the right block. Learn sorted block indexing, step-by-step dry runs, tested C programs, time complexity and practical differences from linear and binary search.
Index narrows the search to three records.
Result: target found at array index 7.Indexed Sequential Search is a two-stage searching technique that first uses an index table to identify a block that may contain the search key, then checks the records in that block sequentially. In the common sorted-array implementation, each index entry stores a block's maximum key and its start/end positions. The method combines block selection with a short linear search.
Imagine a library with 12 books arranged by number. Instead of reading every book's label, you first check a small shelf directory. The directory tells you which shelf holds the possible number. You then inspect only that shelf. Indexed sequential searching follows this directory first, local scan second strategy.
This dedicated chapter covers indexed sequential searching, index tables, block and record pointers, sequential versus binary index scans, complete C implementations, worked examples, complexity and typical exam questions. To revise how to write algorithms and pseudocode, see Algorithm in Data Structure: Characteristics, Steps and Examples .
Chapter roadmap — show contents
- Definition and required terminology
- How to create the index table
- Worked diagram and search
- Algorithm and pseudocode
- Dry runs including not-found
- Interactive index-search lab
- C program using linear index search
- C program using binary index search
- C program with user input
- Time and space analysis
- Block-size choice and construction
- Compare searching methods
- Applications and limitations
- Common mistakes
- Solved exam questions
- MCQs, FAQs and quick notes
What Is Indexed Sequential Search in Data Structure?

In ordinary sequential search, a program checks elements one after another until a match appears. Indexed sequential search improves this idea when data is grouped in ordered blocks. A small index directs the program to a possible block, which is then searched one item at a time.
Primary data
The main sorted array or ordered collection of records. In our example it contains 12 integers, grouped into four blocks of three.
Index table / directory
A smaller collection of entries. Each entry tells us a block's maximum key and the range of record indices belonging to that block.
Block size (b)
The maximum number of items assigned to one block, such as 3. The final block may contain fewer than b records.
Search key and return value
The requested value, such as 31. A matching zero-based array index is returned, or -1 when the key is absent.
Precondition: For this maximum-key index method, the main data is sorted ascending, so block maximum keys are also non-decreasing. Other file indexing schemes exist, but their index definitions and search rules may differ.
Index Table in Indexed Sequential Search
Take the sorted array: [4, 7, 10, 14, 18, 22, 27, 31, 36, 42, 48, 53] . Divide it into four blocks of three elements each. Store the last (maximum) key of every block together with the block's starting and ending array indices.
| Block | Start | End | Maximum index key | Records in block |
|---|---|---|---|---|
| B0 | 0 | 2 | 10 | 4, 7, 10 |
| B1 | 3 | 5 | 22 | 14, 18, 22 |
| B2 | 6 | 8 | 36 | 27, 31, 36 |
| B3 | 9 | 11 | 53 | 42, 48, 53 |
The keys
[10, 22, 36, 53]
are block maximums.
For a target x,
select the
first block whose maxKey ≥ x
.
Then sequentially compare values
only inside that block.
An index containing each block's
first key requires a different
selection rule; do not mix
the two conventions.
Indexed Sequential Search Example with Diagram
Search for 31. Scan maximum keys 10, 22, 36: 31 is larger than 10 and 22 but not larger than 36. Therefore select B2, covering original array indices 6 through 8. Within B2, compare 27 (not equal), then 31 (found). Return index 7.
Indexed Sequential Search Algorithm and Pseudocode
- Start with an ascending sorted array and construct an index of ordered blocks.
- Store maximum key, start index and end index for each block.
- Read the target value.
- Scan index entries until the first maxKey ≥ target is found. If none, return -1.
- Scan the selected block from its start position to its end position.
- If an element equals target, return its array index. If a value exceeds target, stop early because the block is sorted.
- If no match appears, return -1.
This version scans the index sequentially. A second variation uses binary search on the sorted index table , while retaining sequential search inside the selected block. We will implement both in C.
Indexed Sequential Search Dry Run (Found, Missing, Boundary)
| Target | Index maximum checks | Block scan | Result |
|---|---|---|---|
| 31 | 10, 22, 36 | B2: 27, 31 | Index 7 |
| 22 | 10, 22 | B1: 14, 18, 22 | Index 5 |
| 25 | 10, 22, 36 | B2: 27 > 25 | Not found (-1) |
| 60 | 10, 22, 36, 53 | No eligible block | Not found (-1) |
| 4 | 10 | B0: 4 | Index 0 |
| 53 | 10, 22, 36, 53 | B3: 42, 48, 53 | Index 11 |
When a selected block's first value is already greater than the key (such as 27 for target 25), that target is absent. The next block cannot help because all later blocks contain still larger values. The algorithm stops correctly.
Duplicates across blocks: If equal values occur at the boundary of two blocks, choosing the first block whose maximum is at least the target and scanning from its beginning returns the first occurrence in the globally sorted array. Avoid selecting the last equal index entry when the task specifically asks for the first occurrence.
Interactive Indexed Sequential Search Simulator
Try target 31, 25, 4 or 60. Choose sequential index scanning or binary index scanning and inspect each decision. Purple identifies the current index/record check, orange shows the chosen block and green marks a successful record.
Index Map Control Desk
0 comparisonsINDEX TABLE — MAXIMUM KEY OF EACH BLOCK
MAIN SORTED ARRAY
Ready. Press Start and follow the search.
Simulator uses 12 fixed values and block size 3, solely for learning. It does not send input anywhere.
Indexed Sequential Search in C Using an Index Table
This complete C11 program builds an index using each block's last value as its maximum key. It performs sequential search on the index, then scans the selected block. The 12-element array and block size 3 match our diagram.
#include <stdio.h>
#define BLOCK 3
typedef struct {
int maxKey, start, end;
} Entry;
int makeIndex(const int a[], int n, Entry index[]) {
int count = 0;
for (int start = 0; start < n; start += BLOCK) {
int end = start + BLOCK - 1;
if (end >= n) end = n - 1;
index[count++] = (Entry){a[end], start, end};
}
return count;
}
int indexedSearch(const int a[], const Entry index[],
int blocks, int key) {
for (int b = 0; b < blocks; b++) {
if (key <= index[b].maxKey) {
for (int i = index[b].start;
i <= index[b].end; i++) {
if (a[i] == key) return i;
if (a[i] > key) return -1;
}
return -1;
}
}
return -1;
}
int main(void) {
int a[] = {4, 7, 10, 14, 18, 22,
27, 31, 36, 42, 48, 53};
int n = (int)(sizeof a / sizeof a[0]);
Entry index[(sizeof a / sizeof a[0] + BLOCK - 1)
/ BLOCK];
int blocks = makeIndex(a, n, index);
for (int b = 0; b < blocks; b++)
printf("B%d: max=%d, range=%d..%d\n", b,
index[b].maxKey, index[b].start,
index[b].end);
printf("Find 31: index %d\n",
indexedSearch(a, index, blocks, 31));
printf("Find 25: index %d\n",
indexedSearch(a, index, blocks, 25));
return 0;
}
Code explanation:
makeIndex() saves the
end value and boundaries for each block.
indexedSearch() selects
the first index entry whose maxKey
can cover the target.
Only the selected block gets
record comparisons.
Return -1 when the key
does not appear.
Indexed Sequential Search Using Binary Search on the Index in C
Here the index directory itself is searched using binary search . The smallest index maximum at least as large as the target determines the candidate block. The search inside that block remains sequential. The index search costs O(log m), where m is the number of index entries.
#include <stdio.h>
#define BLOCK 3
typedef struct {
int maxKey, start, end;
} Entry;
int buildIndex(const int a[], int n, Entry idx[]) {
int m = 0;
for (int s = 0; s < n; s += BLOCK) {
int e = s + BLOCK - 1;
if (e >= n) e = n - 1;
idx[m++] = (Entry){a[e], s, e};
}
return m;
}
int searchBinaryIndex(const int a[], const Entry idx[],
int m, int key) {
int low = 0, high = m;
while (low < high) {
int mid = low + (high - low) / 2;
if (idx[mid].maxKey < key) low = mid + 1;
else high = mid;
}
if (low == m) return -1;
for (int i = idx[low].start;
i <= idx[low].end; i++) {
if (a[i] == key) return i;
if (a[i] > key) break;
}
return -1;
}
int main(void) {
int a[] = {4, 7, 10, 14, 18, 22,
27, 31, 36, 42, 48, 53};
int n = (int)(sizeof a / sizeof a[0]);
Entry idx[(sizeof a / sizeof a[0] + BLOCK - 1)
/ BLOCK];
int m = buildIndex(a, n, idx);
printf("31 -> %d\n", searchBinaryIndex(a, idx, m, 31));
printf("25 -> %d\n", searchBinaryIndex(a, idx, m, 25));
printf("60 -> %d\n", searchBinaryIndex(a, idx, m, 60));
return 0;
}
Why first max ≥ key matters: The binary index procedure behaves like a lower-bound operation on maximum keys. It finds the earliest eligible block even if a repeated key appears at a block boundary. A plain binary search returning an arbitrary equal maximum could select the wrong block for a first-occurrence requirement.
Indexed Sequential Search C Program with User Input
This practical program accepts up to 100 sorted integers, a block size and a target. It validates the ascending order and uses an index with up to 100 entries. The final block can be shorter, so the method also works when n is not divisible by block size.
#include <stdio.h>
#define CAP 100
typedef struct {
int maxKey, start, end;
} Entry;
int main(void) {
int a[CAP], n, size, key;
Entry idx[CAP];
int m = 0;
printf("Number of values (0..100): ");
if (scanf("%d", &n) != 1 || n < 0 || n > CAP)
return 1;
printf("Enter ascending sorted integers:\n");
for (int i = 0; i < n; i++) {
if (scanf("%d", &a[i]) != 1) return 1;
if (i > 0 && a[i] < a[i - 1]) {
puts("Data must be sorted ascending.");
return 1;
}
}
printf("Block size (1..100): ");
if (scanf("%d", &size) != 1 ||
size < 1 || size > CAP) return 1;
for (int s = 0; s < n; s += size) {
int e = s + size - 1;
if (e >= n) e = n - 1;
idx[m++] = (Entry){a[e], s, e};
}
printf("Target: ");
if (scanf("%d", &key) != 1) return 1;
int answer = -1;
for (int b = 0; b < m; b++) {
if (key <= idx[b].maxKey) {
for (int i = idx[b].start;
i <= idx[b].end; i++) {
if (a[i] == key) {
answer = i;
break;
}
if (a[i] > key) break;
}
break;
}
}
printf("Index: %d\n", answer);
return 0;
}
Empty input:
For n = 0 no blocks are created
and the result is -1.
Input block size must stay positive;
zero would otherwise cause a
non-terminating block-construction loop.
If your teacher asks to display the
index table, print
idx[b].maxKey,
idx[b].start
and idx[b].end
after building it.
Compile in VS Code:
Save each example in the filename
shown above.
For this program, run
gcc -std=c11 -Wall -Wextra indexed_search_input.c -o indexed_search_input,
then indexed_search_input.exe
on Windows.
Compile the other two programs
separately because each has
its own main().
Indexed Sequential Search Time and Space Complexity
Let n be the number of records, b the maximum block size and m = ceil(n/b) the number of index entries. The index scan and the record scan contribute separate costs.
| Operation / approach | Cost | Explanation |
|---|---|---|
| Sequential index scan | O(m) | May inspect all m block maximum keys |
| Binary index scan | O(log m) | Sorted index table is halved each step |
| Scan selected block | O(b) | At most b element comparisons |
| Full sequential-index search | O(n/b + b) | Index search plus one block scan |
| Full binary-index search | O(log(n/b) + b) | Binary index search plus one block scan |
| Index storage | O(n/b) | One index entry per block |
| Index construction | O(m) on a sorted array | Read each block ending directly using random access |
Best-case: With a sequential index, the target may match the first record of the first selected block, requiring constant comparisons: O(1). In binary-index mode, locating the candidate index generally takes O(log m), even if the target is the first record inside the block.
Worst-case: Sequential index lookup followed by linear block scan takes O(m + b). Without choosing b appropriately, this can approach O(n): b = 1 means m = n; b = n means the whole dataset is one block.
Why Is Block Size Often Chosen Near √n?
With a sequential index, making blocks
too small increases the number of
index entries; making blocks too large
increases the number of values scanned
within a block.
The expression n/b + b
balances these costs when b is
near √n.
| Example n = 100 | Block size b | Index entries m | Upper-bound sum m + b |
|---|---|---|---|
| Small blocks | 2 | 50 | 52 |
| Balanced blocks | 10 | 10 | 20 |
| Larger blocks | 20 | 5 | 25 |
| One large block | 100 | 1 | 101 |
These values represent a simple upper-bound count of possible index-plus-block checks, not measured execution times. If the index is searched with binary search, the balance is different; the exact best b depends on memory, CPU, disk page size, records and workload. A √n block size is mainly a helpful theoretical teaching choice for sequentially scanned indices.
When preparing the index, an already sorted array lets us select each block's ending key in O(1) time, so building m entries takes O(m). If we must sort unsorted input first, the sorting cost is separate and must not be ignored.
Indexed Sequential vs Linear vs Binary vs Jump Search
| Feature | Linear Search | Binary Search | Indexed Sequential Search | Jump Search |
|---|---|---|---|---|
| Sorted input | Not required | Required | Required in this design | Required |
| Main action | Scan whole collection | Halve full array | Search index, scan one block | Jump blocks, scan local part |
| Worst search time | O(n) | O(log n) | O(n/b + b) sequential index | O(√n) with suitable step |
| Extra index storage | None | None | O(n/b) | Usually none |
| Typical teaching use | Simple unsorted data | Sorted random-access arrays | Block-oriented directory search | Block-jump comparisons |
Indexed sequential search vs jump search: Both can end with a sequential scan inside a small block. However, indexed sequential searching maintains an explicit block directory. Jump search commonly moves through a sorted array at regular jumps without keeping a separate persistent index table.
Indexed sequential vs ISAM: Indexed Sequential Access Method (ISAM) is a historical indexed-file organisation with storage and update details beyond this classroom array search. Do not treat the simple array demonstration as a full ISAM database engine.
Applications, Advantages and Disadvantages
Applications
- Locating a record in a sorted, block-organised file.
- Teaching sparse index tables and record offsets.
- Simple directories over sorted batches of IDs or marks.
- Understanding why disk-based systems often index groups of records.
Advantages
- Scans far fewer records than full linear search when blocks are well chosen.
- Easy to explain using a small index table.
- Allows the index to be searched linearly or by binary search.
- Index contains one entry per block rather than one per record.
Limitations
- Needs ordered, correctly indexed blocks in our version.
- Index consumes extra storage.
- Updates may require changing block boundaries and index entries.
- Small blocks increase index work; large blocks increase local scans.
When to choose it
Use it to illustrate block-based searching or when data naturally lives in sorted blocks with a manageable index. For an ordinary sorted array held in memory, direct binary search of the full array is usually asymptotically faster .
Common Indexed Sequential Search Mistakes
- Mixing index definitions: A maximum-key index must select the first maxKey ≥ target; a first-key index uses a different rule.
- Scanning the wrong range: Always use the block's actual start and end positions, including a short final block.
- Assuming an unsorted array is valid: Maximum keys do not correctly locate targets if the blocks have no consistent global ordering.
- Returning the block number as the item index: B2 is the block, but 31 is at array index 7.
- Ignoring duplicates: For the first occurrence, select the earliest eligible block, especially when equal values cross block boundaries.
- Claiming universal O(log n): The selected block is scanned sequentially, adding O(b) even if the index uses binary search.
- Ignoring index-building and update costs: Searching time alone does not include all work for preparing data and maintaining the index.
- Using block size 0: This can cause invalid arithmetic or endless loops. Validate it before building the index.
Important Indexed Sequential Search Questions with Answers
The following are original PYQ-style practice questions, not claimed as real previous-year questions from a particular university.
Q1. Define indexed sequential search.
It is a searching technique that uses a small index to identify the appropriate data block and then performs sequential search inside that block.
Q2. What is an index table?
An index table contains block keys and locations, allowing a search algorithm to quickly identify which block may hold the target.
Q3. What is the purpose of block size?
Block size controls how many records belong to each group, affecting index size and the maximum local scanning work.
Q4. Explain indexed sequential search with an example.
Take sorted array [4,7,10,14,18,22,27,31,36,42,48,53] and divide into blocks of three. Build maximum-key index [10,22,36,53]. To search 31, first find maximum 36 in the index, choose B2 (indices 6–8), then compare 27 and 31. Return index 7. The index reduces the data range to scan.
Q5. Differentiate sequential, binary and indexed sequential search.
Sequential search scans a collection without requiring sorting and has O(n) worst-case time. Binary search halves an already sorted indexed array in O(log n) time. Indexed sequential search uses a block index followed by linear search within the chosen block; for an index scanned sequentially, it takes O(n/b + b).
Q6. Explain algorithm, diagram, C program and time complexity.
Define indexed sequential search; draw the main sorted array split into blocks and the index table storing maximum key and start/end position. Write the steps from Section 4, trace searching 31, and reproduce the complete C program from Section 7. With n records, block size b and m = ceil(n/b), sequential index selection costs O(m), the block scan costs O(b), total O(m + b) = O(n/b + b). For b near √n, worst-case time is O(√n), with O(m) index storage.
Q7. Explain an unsuccessful search for 25.
Check index maxima 10, 22, 36 and select B2 because 36 is the first maximum not less than 25. Scan B2 beginning at 27. Since 27 already exceeds 25 and data is sorted, return -1. This illustrates why the sorted-data assumption matters.
MCQs, FAQs and Quick Revision
Practice MCQs (with explanations)
- Indexed sequential search first checks: A. Stack B. Index table C. Whole file D. Graph. Answer: B. The index selects a possible block.
- After selecting the block, which search is used in this method? A. DFS B. Sequential C. Hash D. Merge. Answer: B. The chosen block is scanned in order.
- Index maxima [10,22,36,53]; target 31 belongs to: A. B0 B. B1 C. B2 D. B3. Answer: C. First maximum ≥ 31 is 36.
- What is m if n = 100, b = 10? A. 100 B. 10 C. 1 D. 1000. Answer: B. ceil(100/10) = 10.
- Sequential-index worst time? A. O(n/b + b) B. O(1) always C. O(log n) always D. O(n²). Answer: A. Index scan + local scan.
- Index storage for m blocks? A. O(1) B. O(m) C. O(n²) D. O(log log n). Answer: B. One entry per block.
- Binary search of m index entries costs: A. O(m²) B. O(m) C. O(log m) D. O(1) always. Answer: C. Halves index interval.
- Which record index stores 31 in the sample array? A. 2 B. 6 C. 7 D. 8. Answer: C. Zero-based index 7.
Frequently Asked Questions
What is indexed sequential search in simple words?
It means checking a small block directory first and then examining records only inside the likely block.
Does indexed sequential search need sorted data?
The maximum-key sorted-array version in this article does. Different indexing schemes may have different requirements, but our method relies on ordered blocks and an ordered index.
What is the time complexity of indexed sequential search?
If m is the number of index entries and b is block size, scanning the index and then a block takes O(m + b), or O(n/b + b). Binary searching the index changes it to O(log m + b).
What is the difference between indexed sequential search and binary search?
Binary search directly halves the full sorted array. Indexed sequential search identifies a block using an index, then scans records within that block.
What does an index entry contain?
In our example, each entry contains the block's maximum key and its start/end array indices. File-based systems may use record or disk-block addresses.
Can the index itself use binary search?
Yes. Because maximum keys are ordered, a lower-bound binary search can find the first block maximum at least equal to the target in O(log m) time.
What if the last block has fewer values?
Store its actual ending index. The program must stop at that boundary rather than assuming all blocks have exactly b records.
Is indexed sequential search the same as ISAM?
No. This is a basic two-stage indexed search algorithm. ISAM is a more specific indexed sequential file organisation with additional storage-management concepts.
Quick revision
Sorted records → build index → select first eligible block → sequential scan → return index or -1.
Important formulas
m = ceil(n/b). Sequential-index search: O(m+b). Binary-index search: O(log m+b). Index space: O(m).
Conclusion: Use a Small Index to Search a Smaller Block
Indexed sequential search combines a compact directory with straightforward sequential searching. The idea is to avoid scanning an entire ordered dataset when a block index can narrow the possible location first.
For exams, practise constructing the index table, selecting the first block with a suitable maximum key, tracing the local scan and deriving O(n/b + b) from its two stages. Once these steps are clear, the C implementation becomes much easier to understand.
