Static vs Dynamic Data Structures
A static data structure has a fixed size that must be determined at compile time or at allocation time, and cannot be resized during runtime without creating an entirely new structure. Arrays in languages like C or Java (primitive arrays) are the canonical example — once allocated, their size is fixed.
A dynamic data structure can grow or shrink in size at runtime, typically by allocating and deallocating memory as needed. Linked lists, dynamic arrays (like ArrayList, Vector, or Python lists), and trees are dynamic, as they adjust their memory footprint based on the number of elements they hold.
Static: fixed size, contiguous memory, fast index-based access, e.g., primitive arrays
Dynamic: resizable, may use non-contiguous memory (e.g., linked lists) or amortized resizing (e.g., dynamic arrays)
Static structures avoid resizing overhead but risk overflow or wasted space
Dynamic structures adapt to workload but may incur pointer overhead or occasional resizing cost