# Static and Dynamic Data Structures – Explained to Kids

This post is also available in: हिन्दी (Hindi) العربية (Arabic)

In computer science,  a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data, i.e., it is an algebraic structure of data. Data Structures are used to reduce the complexity (mostly the time complexity) of the code.

Depending on your requirement and project, it is important to choose the right data structure for your project. For example, if you want to store data sequentially in the memory, then you can go for the Array data structure.

There are various types of data structures used in different programming languages based on requirements. These data structures can be broadly classified as – Static Data Structure And Dynamic Data Structure.

## Static Data Structures

A static data structure is an organization or collection of data in memory that is fixed in size. This results in the maximum size needing to be known in advance, as memory cannot be reallocated at a later point. Arrays are a prominent example of a static data structure.

A key advantage of static data structures is that with memory allocation fixed, no control or oversight is needed to prevent potential overflow or underflow issues when adding new items or removing existing ones. This makes static data structures easier to program but at the expense of potential efficiency in terms of memory consumption.

### Features of Static Data Structures

The prime features of static structures are:

• None of the structural information needs to be stored explicitly within the elements – it is often held in a distinct logical/physical header;
• The elements of an allocated structure are physically contiguous, held in a single segment of memory;
• All descriptive information, other than the physical location of the allocated structure, is determined by the structure definition;
• Relationships between elements do not change during the lifetime of the structure.

Relaxation of these features leads to the concept of a dynamic data structure.

## Dynamic Data Structures

Dynamic data structures are those whose organizational characteristics may change during their lifetime. The adaptability afforded by such structures, e.g. linked lists, is often at the expense of decreased efficiency in accessing elements of the structure.

Two main features distinguish dynamic structures from static data structures. Firstly, it is no longer possible to infer all structural information from a header; each data element will have to contain information relating it logically to other elements of the structure. Secondly, using a single block of contiguous storage is often not appropriate, and hence it is necessary to provide some storage management scheme at run-time.

### Features of Dynamic Data Structures

The prime features of static structures are:

• It is no longer possible to infer all structural information from a header; each data element will have to contain information relating it logically to other elements of the structure.
• Using a single block of contiguous storage is often not appropriate, and hence it is necessary to provide some storage management scheme at run-time.

## Difference Between Static and Dynamic Data Structures

The static data structure has a fixed memory size whereas, in a dynamic data structure, the size can be randomly updated during the run time which may be considered efficient with respect to the memory complexity of the code. Static data structure provides easier access to elements with respect to a dynamic data structure. Unlike static data structures, dynamic data structures are flexible.

## Pros and Cons of Static Data Structures

##### Pros
• Compiler and allocate space during compilation
• Easy to program
• Easy to check for overflow
• An array allows random access
##### Cons
• Programmers have to estimate the maximum amount of space that is going to be needed
• Can waste a lot of space (if the estimate was too high)

## Pros and Cons of Dynamic Data Structures

##### Pros
• Only uses the space needed at any time
• Makes efficient use of memory
• Storage no longer requires can be returned to the system for other uses
##### Cons
• Difficult to program
• Can be slow to implement searches
• A linked list only allows serial access (starting at the beginning and going through one at a time

## Practice Problems

1. What is data structure in programming?
2. What is a static data structure?
3. List out any two static data structures.
4. What is a dynamic data structure?
5. List out any two dynamic data structures.
6. What is the difference between static and dynamic structure?

## FAQs

### What is static and dynamic data structure give example.

Static data structures are helpful/used in scenarios where we know the size of the data prior. Examples include arrays. Dynamic data structures can be used in all cases. Examples include linked lists, stack, queue, tree, etc.

### What are static data structures?

A static data structure is an organization or collection of data in memory which have a fixed size, that is, it can store a limited amount of elements or data in it. An array is an example of a static data structure.

### Which is dynamic data structure?

A dynamic data structure has a dynamic size, that is, its size can grow and shrink based on the elements present in it at runtime. It makes efficient use of memory by using only that amount of space in memory that is required at any time. Dynamic memory allocation can be done in both the stack and the heap.

## Conclusion

A data structure is a data organization, management, and storage format that enables efficient access and modification. There are two types of data structures – Static and Dynamic. A static data structure is an organization or collection of data in memory which have a fixed size, that is, it can store a limited amount of elements or data in it. A dynamic data structure has a dynamic size, that is, its size can grow and shrink based on the elements present in it at runtime.