- 2073 Magh · 2 marks
Linked list has no random access
Short answer
Nodes in a linked list are not contiguous in memory; there is no index formula. Accessing element k requires starting at the head and following next pointers k-1 times, which takess O(n) worst-case time, whereas arrays allow O(1) random access.
In a linked list data cannot be accessed randomly. Justify with suitable example.
In a linked list the nodes are scattered in memory, and the only way to reach a node is through the pointer stored in the node before it. There is no formula like address = base + i × size as in an array. To get the k-th node we must start at start and follow next k-1 times, so access takes O(k) time (O(n) worst case); an array gives A[k] in O(1).
Example: list start -> [10] -> [20] -> [30] -> [40]. To read the 4th element, we visit 10, 20, 30 and only then reach 40; we cannot jump directly to 40.
p = start;
for (i = 1; i < 4; i++) p = p->next; /* 3 steps */
printf("%d", p->info); /* 40 */
Hence data in a linked list cannot be accessed randomly, only sequentially.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Polynomial addition using linked list · Data Structure and Algorithm, chapter 4 · asked 3×
- Types of linked list · Data Structure and Algorithm, chapter 4 · asked 2×
- Insert and delete kth node in doubly linked list · Data Structure and Algorithm, chapter 4 · asked 2×
- Doubly vs singly linked list · Data Structure and Algorithm, chapter 4 · asked 2×
- Stack and queue using linked list · Data Structure and Algorithm, chapter 4 · asked 2×
- ADT of linked list · Data Structure and Algorithm, chapter 1
- Random access file transaction processing · Object Oriented Programming, chapter 8
- File I/O operations, errors, random access · Computer Programming, chapter 10
- Pixel access rate of raster system · Computer Graphics, chapter 1
- Star-delta transformer cannot parallel with star-star · Electrical Machines, chapter 2