A static data structure has a fixed capacity once it is created, whereas a dynamic data structure can grow or shrink while a program is running. The main difference is therefore how their size and memory allocation are managed.
In IB Computer Science B2.2, a static structure is commonly represented by an array. When an array of 100 integers is created, memory for all 100 elements is reserved, even if only 20 are currently used. Adding a 101st element requires creating a larger array and copying the existing data.
A dynamic structure, such as a linked list, allocates memory as elements are added. Each element is stored in a node containing data and a pointer or reference to another node. Nodes can be inserted or removed without recreating the entire structure.
| Feature | Static data structure | Dynamic data structure |
|---|---|---|
| Size | Fixed after creation | Can change during execution |
| Memory allocation | Reserved as a fixed block | Allocated and released as required |
| Storage | Usually contiguous | May be non-contiguous |
| Element access | Array indexing usually gives direct access in time | A linked list usually requires sequential traversal in time |
| Memory costs | May waste unused capacity | Requires extra memory for pointers or references |
| Typical example | Fixed-size array | Linked list |
Dynamic structures provide flexibility, but they are not automatically more efficient. Their nodes require additional memory, and traversal can be slower than direct array access.
A common misconception is that stacks and queues are always dynamic. They are abstract data types and may be implemented using either a fixed-size array or a dynamic linked structure.
For an IB exam question using the command term distinguish, state the fixed-versus-variable size difference and support it with examples. For an evaluate question, compare memory usage, access speed, insertion and deletion, then justify which structure best suits the stated scenario.