Data Structures is a term that we hear in every single moment in a project. In this series of posts, I will handle the concept of data structures for absolute beginners. I will not dive deeply inside the magic of complex data structures. So Let’s Start!
First, let’s agree that data is central point that we write software to handle. When we say data in a program, we mean by that two kinds of them: the first is the internal data, which are variables in the same binary file (e.g. int x = 5; //x contains data ), and the second is external data, which are represented in external files or databases. We will not discuss files or databases here.
Suppose that you are working in a software program and you are writing variables. You simply define variables and give them values. The problem comes when there are TOO MANY variables. How are we going to handle them effectively ?! You may got stuck in them and don’t know which variable is for what ! Unfortunately, the names of variables are not enough to handle them effectively.
Let’s illustrate the concept with a simple example. Suppose that you are required to write a program that manage the names of 100 employees in a company. You may write the following code:
string employee1 = "Ahmed"; string employee2 = "Mohammed"; string employee3 = "Ali"; : : : string employee4 = "HUH. I forgot his name!";
It seems very simple , but I bet you can handle them after declaration (even if you got the time to write them down :D).
And here comes Data Structures. As the name implies, it’s about how to put data in a well-defined format that we can handle easily.
Note: As we mentioned that we use data structures to represent internal data during the run-time of the application, files (and file structures) and databases are used to handle data that are external to the application.
This is one of the problems that require using data structures. There will be problems regarding handling memory locations. Sometimes, the data we represent follows a specific pattern. All these points (but not limited to) requires that we must use a technique to handle them, Data Structures!
Data Structures are based mainly on the concept of memory management. When we define variables, they are assigned memory location. Each location has an address. Data Structures (as the name implies) is how to manage these memory locations in structured representations. When we define a Data Structure, we define the way they are stored in memory (either sequentially or scattered) and the operations we do on them. These are the two characteristics that differentiate a data structure from another. At this point, comes the so-called Abstract Data Type. ADT defines the operations we can do on the data, regardless of any particular implementation. For example, we will have a list data structure, we can add, delete, update items in the list. We do so in a manner that don’t care about how it’s implemented. (I can add, delete, update .. I don’t need to know how it’s implemented.). In fact, we are going to describe, here, how they are implemented. After that, we will know how to use them.
I think that all of us used a data structure in his introduction courses. You may have not noticed that, but you already used an ARRAY! The array is simplest data structure used in high-level programming languages. And we must mention that lower-level programming languages does not necessarily provide a data structure (like some assembly programming), we have to implement ours.
Enough for now! In the next post, I’m going to discuss data structure implementations in C++. So, Stay tuned.
Your feedback and suggestions are very welcomed :).