Static vs Dynamic Data Structures and Arrays

Static vs Dynamic Data Structures and Arrays

A data structure is a way of organizing values in memory so that a program can store, find, and change them efficiently. Before we study the more elaborate structures in this unit, we need a firm grip on the most basic distinction of all: whether a structure has a fixed size decided in advance, or whether it can grow and shrink while the program runs. This distinction shapes every design decision that follows.

Static data structures

A static data structure is allocated a fixed block of memory when the program is compiled or when the structure is created, and that size cannot change afterward. The classic example is the array. If you declare an array of 30 integers, the computer reserves exactly enough contiguous memory for 30 integers, no more and no less. The great advantage is speed and