- Asked 2/14
- 2072 Asoj · 6 marks
- 2071 Bhadra · 6 marks
Static vs dynamic implementation of list
Short answer
Static list (array) has fixed size, contiguous memory, O(1) index access, but insertion/deletion requires shifting elements O(n). Dynamic list (linked nodes) allocates memory at runtime, uses pointers, allows O(1) insertion/deletion after position is found, but sequential access O(n).
Differentiate between static and dynamic implementation of list with suitable example.
A list is a linear collection of elements in a sequence. It can be implemented statically (array) or dynamically (linked nodes with pointers).
| Static implementation (array) | Dynamic implementation (linked list) |
|---|---|
| Elements stored in contiguous memory | Nodes stored anywhere; linked by pointers |
| Size fixed at compile time | Size changes at run time |
| Memory is allocated even if unused | Memory allocated only when a node is needed |
| Insertion/deletion in the middle needs shifting of elements: O(n) | Only pointers change once the position is known: O(1) |
| Random access by index: O(1) | Sequential access only: O(n) |
| No extra memory for links | Extra memory for the pointer in every node |
| Overflow when array is full | Overflow only when heap is exhausted |
| Memory freed only at program end | Memory returned with free() |
Example: list 10, 20, 30
Static:
int list[100] = {10, 20, 30}; // n = 3
// insert 15 at index 1: shift 20, 30 right -> 10 15 20 30
Dynamic:
struct node { int info; struct node *next; };
// head -> [10|*] -> [20|*] -> [30|NULL]
// insert 15 after 10: p->next = q->next; q->next = p; (no shifting)
Choose arrays when the size is known and fast access is needed; choose linked lists when size varies and insertions/deletions are frequent.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Static vs dynamic implementation of stack · Data Structure and Algorithm, chapter 2
- Static vs dynamic list; getnode and freenode · Data Structure and Algorithm, chapter 3
- Why choose static or dynamic list · Data Structure and Algorithm, chapter 3
- Array list; static or dynamic choice · Data Structure and Algorithm, chapter 3
- Static and dynamic data structures; array list · Data Structure and Algorithm, chapter 3
- Dynamic implementation of queue · Data Structure and Algorithm, chapter 4
- Static vs dynamic mathematical model · Simulation and Modeling, chapter 2 · asked 3×
- Static and dynamic performance parameters · Instrumentation I, chapter 2
- Static versus dynamic balancing · Theory of Mechanism and Machine II, chapter 5
- Static and dynamic hazards and their elimination · Digital Logic, chapter 3 · asked 2×