Past exam question: 2072 Ashwin (Regular), Q4
Open in the Padhaiko appQuestion
Differentiate static and dynamic implementation of list with suitable example.
Solution
Static vs. Dynamic List Implementation:
| Feature | Static Implementation (Array) | Dynamic Implementation (Linked List) |
|---|---|---|
| Allocation Time | Compile-time fixed array items[MAX] | Runtime per-node malloc/free |
| Capacity | Fixed upper limit MAX | Flexible; bounded only by heap RAM |
| Memory Layout | Contiguous block | Non-contiguous scattered nodes via pointers |
| Access Speed | direct index lookup | sequential traversal |
| Insert / Delete | element shifting | pointer rewiring once located |
Example: Suppose a list holds [10, 20, 30] and we insert 5 at index 0:
- In a static array
A[100],30, 20, 10must shift right to indices3, 2, 1before writingA[0] = 5. - In a linked list
head -> 10 -> 20 -> 30, we simply allocate[5]and set5->next = head; head = 5without moving existing nodes.
Answer:
Static lists use fixed contiguous arrays ( indexing, shifting), whereas dynamic lists use heap-allocated pointer-linked nodes (flexible capacity and head/middle splicing once located, with access).