Data Structures: Static VS Dynamic

--

If you are interested in computer science, or you are a developer, you’ve probably heard of these two terms. If not, no worries! You’ll hear about them soon because they are very important concepts in computer science and more particularly in programming.

Before diving into the details of these two mysterious yet important concepts, let’s know first what is a data structure?

Data structures:

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 apply to the data.

Efficient access and modification?! What does that mean?

Well, it means that the different operations on our data will take less time and less space on the physical memory of our computers. In other words, using data structures helps us reduce the complexity (the time and space complexity) of our algorithm.

PS: no worries if you don’t know what is time or space complexity, you’ll get to know them in time.

Knowing how to organize your data using the right data structure to solve a particular problem in less time and less space is crucial.

Now we have an idea about what is a data structure, let’s dive deeper into it.

Types of data structures:

Data structures can be divided into two types of families which are :

Static data structures and Dynamic data structures.

So what is the difference between these two data structures?

Small wisdom: “while trying to figure out the difference between two things, it’s crucial to understand the meaning of each one of them”.

The logic says we follow the wisdom that we’ve just read, doesn’t it?

So here we go with the definitions again!

What are static data structures?

What you need to know about a static data structure is that its size is fixed before running the program, also it takes a fixed space on the memory of the computer, so the content of the data structure can be modified but without changing the memory space allocated to it.

The process of taking a place on the memory is called the allocation. In static data structures, we have a static allocation.

Too much information at once, right?

Well, maybe a small example here can help.

Let’s take arrays as an example.

So, arrays (or tables) are a good example to illustrate static data structures.

  • Before using an array in our program, we need to declare it first. When declaring, we need to precise its size X.
  • Once we’ve given our array a fixed size, our program asks the operating system for permission to use X contiguous memory boxes for our table which means giving our array a fixed space in the physical memory!

Contiguous memory boxes: it means that these memory boxes are situated one after another.

What are dynamic data structures?

Unlike static data structures, the dynamic data structures’ size is not fixed and can be modified while running the program, and the space taken in memory by these structures is not fixed too. In dynamic data structures, we have a dynamic allocation.

Do you want an example here too? Well, here we go!

Linked lists are a dynamic data structure.

  • When using a linked list in our program, we need to declare it first, but we don’t need to indicate its size in this declaration, which means that this size is not fixed and can be modified while running our program.
  • Unlike tables, linked lists don’t have a fixed memory space allocated to them. Also, this memory space doesn’t have to be contiguous memory boxes like in arrays.
  • And during the execution of the program manipulating the data, new elements can be added (linked to our list).

And we’ve finally finished with definitions! The differences between the two structures are clear now, aren’t they?

If you want a small summary of what you’ve just read, well, don’t worry, we’ve prepared this small outline just for you!

TL; DR:

STATIC data structures VS DYNAMIC data structures:

  • The size: We already know from the definitions above that the size in static data structures is fixed, whereas it’s not fixed in dynamic data structures, and it can be updated while running our program.
  • Access: Static data structures provide easier access to elements than dynamic ones.
  • Flexibility: Dynamic data structures are more flexible.
  • Efficiency: Dynamic data structures are more efficient concerning the space complexity of our program.

Written by: Besma BOUHOUFANI, 2nd year student at ESI and Communication Assistant of CSE Club Scientifique de l’ESI.

--

--

CSE Club Scientifique de l’ESI

A club of passionate algerian students who aim for promoting both the contribution of students community to the country’s development, and youth empowerment.