- 2069 Bhadra · 2+4 marks
Static and dynamic data structures; array list
Short answer
Static data structures have fixed compile-time size and contiguous memory; dynamic structures change size at run time using allocation and pointers. Array list stores elements consecutively with a count n; limitations are fixed MAX causing overflow or wasted memory, O(n) shifting on insert/delete, contiguous block requirement, and costly resizing.
What do you mean by static and dynamic data structures? Explain array implementation of list with its limitations.
Static and dynamic data structures
A static data structure has a fixed size decided at compile time. Memory is allocated once and cannot grow or shrink at run time. Example: an array int a[100];.
A dynamic data structure can change its size during execution; memory is requested (malloc) and released (free) as needed. Examples: linked list, dynamic stack/queue, tree.
| Static | Dynamic |
|---|---|
| Size fixed at compile time | Size changes at run time |
| Memory may be wasted or insufficient | Memory used as needed |
| Elements stored contiguously | Elements scattered, joined by pointers |
| Fast direct access by index | Sequential access only |
| Insertion/deletion needs shifting | Only pointers change |
| Example: array | Example: linked list |
Array implementation of a list
The elements of the list are stored in consecutive locations of an array, and a variable n (or last) records how many elements are present. The i-th element is list[i], so the order of elements is given by the physical order in memory.
list[] 10 20 30 40 _ _ MAX = 6
index 0 1 2 3 4 5 n = 4
- Insert at k: if n = MAX report overflow; else shift
list[k..n-1]one place right, put the item atlist[k], n = n + 1. - Delete at k: if n = 0 report underflow; else shift
list[k+1..n-1]one place left, n = n - 1.
int insert(int list[], int *n, int k, int x) {
if (*n == MAX) return 0;
for (int i = *n - 1; i >= k; i--) list[i + 1] = list[i];
list[k] = x; (*n)++;
return 1;
}
Limitations
- Size is fixed; the list cannot grow beyond MAX (overflow), and a big array wastes memory if only few items are stored.
- Insertion and deletion in the middle need shifting of many elements: O(n) time.
- The array must occupy one contiguous block, which may not be available.
- Size cannot be changed at run time; resizing means allocating a new array and copying.
- Elements of different types cannot be mixed, and deleted slots stay reserved.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Array list; static or dynamic choice · 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
- Why choose static or dynamic list · 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×
- Static and dynamic routing algorithms · Telecommunications, chapter 8
- Dynamic memory for object and object array · Object Oriented Programming, chapter 3
- Static vs dynamic mathematical model · Simulation and Modeling, chapter 2 · asked 3×