Skip to main content

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)

All Data Structure and Algorithm chapter 4 questions →