- 2070 Bhadra · 3+3 marks
Array list; static or dynamic choice
Short answer
Array implementation stores elements in consecutive locations with a count n, giving O(1) access and O(n) insert/delete due to shifting. Choose static when maximum size is known and random access is important; choose dynamic linked list when size varies and many insertions/deletions occur.
Explain array implementation of list. State the reason why would you choose either static implementation or dynamic implementation for list.
Array implementation of a list
A list is a linear sequence of elements. In array (static) implementation the elements occupy consecutive locations of an array LA[0..MAX-1], and an integer n counts the elements in use. The position of an element gives the order.
index: 0 1 2 3 4 ... MAX-1
| 10 | 20 | 30 | 40 | | ... | n = 4
- Access to the i-th element:
LA[i], O(1). - Insert at k: shift
LA[k..n-1]right, store item,n++. O(n). - Delete at k: shift
LA[k+1..n-1]left,n--. O(n). - Overflow when
n == MAX; underflow whenn == 0.
#define MAX 100
int la[MAX], n = 0;
void insert(int k, int item) { /* 0 <= k <= n */
if (n == MAX) { printf("Overflow\n"); return; }
for (int j = n - 1; j >= k; j--) la[j + 1] = la[j];
la[k] = item; n++;
}
Choosing static or dynamic implementation
| Choose static (array) when | Choose dynamic (linked list) when |
|---|---|
| Maximum size is known in advance | Size is unknown or varies a lot |
| Fast random access is needed | Access is mostly sequential |
| Few insertions/deletions in the middle | Many insertions/deletions |
| Memory per element must be small (no pointers) | Extra pointer memory is acceptable |
| Simple code is preferred | Flexible memory use is preferred |
For example, a list of the 12 months is best kept in an array (fixed size, indexed access), while a waiting list of customers whose number changes constantly is best kept as a linked list.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Why choose static or dynamic list · Data Structure and Algorithm, chapter 3
- Static and dynamic data structures; array list · Data Structure and Algorithm, chapter 3
- Static vs dynamic implementation of list · Data Structure and Algorithm, chapter 3 · asked 2×
- Static vs dynamic implementation of stack · Data Structure and Algorithm, chapter 2
- Array implementation of list in C · Data Structure and Algorithm, chapter 3
- Dynamic implementation of queue · Data Structure and Algorithm, chapter 4
- Static and dynamic hazards and their elimination · Digital Logic, chapter 3 · asked 2×
- Dynamic memory for object and object array · Object Oriented Programming, chapter 3
- Static vs dynamic mathematical model · Simulation and Modeling, chapter 2 · asked 3×
- Static versus dynamic binding trade-offs · Object Oriented Programming, chapter 7