Introduction to Data Structures...
Tags: datastructures, beginners, codenewbie, c
Published: 2022-02-13 11:13:08


If there is one thing which you have heard while into programming, it is **Data Structures and Algorithms** or simply **DSA**. It plays a pivotal role if you are sitting for any Tech-Interviews. What types of Data Structure problems are asked in interviews is an important question, but for a beginner how to begin learning Data Structures is the most important question. In this blog we will be dealing with the latter.
Also relevant real life examples of the use of data structures are also included to invoke interest.

**Now, What is Data?**
Data is just any random number or character which in itself does not have any meaning. Data objects are considered mutually unrelated in space.

**So, What is Data Structures?**
-> The most easy definition would be : It is a way of storing data values so that they can be retrieved and used efficiently.
-> A more precise definition would be : It is a particular way of organising a collection of data values, so that information can be arranged, stored, processed & retrieved easily and efficiently.

Next Question will be : **What are the Classifications of Data Structures?**
A: Broadly Data Structures can be classified into 2 types -> Primitive and Non-Primitive. The Chart is given below.
![Classification of Data Structures](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/02uxeve7v83d7cvnc6wr.png)

Now, let us see in brief what each of these data structure means...

**What are Primitive Data Structures?**
A: It is a type of data structure that stores the data of only one type. Integers,Floats,Characters are examples of Primitive Data Structures.

**What are Non-Primitive Data Structures?**
A: It is a type of data structure that can store the data of multiple type. It is of two types -> Linear and Non-Linear.

**Linear Data Structure** -> In this type the data elements are stored in a linear way. It is a non-hierarchical way of storing data. 

<u>**Linear Data Structures**</u>

- **Arrays** : It is simply a collection of similar data types. Although various other modifications are present in different languages. In languages such as C, array elements occupy contiguous memory locations and the size is declared at compile time. Thus the term static relates to it.

- **Linked-List** : It is a collection of nodes, which are randomly allocated in the memory i.e. Dynamically allocated. Each node contains the data field and the address of the next node. A pictoral representation is shown below:

![Linked List representation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pe4oygpto69ibou4o8a7.png)
_Fact_ : The music player in your smartphone is most probably using Linked List to fetch music for you.

- **Stacks** : It is a type of linear data structure which follow the Last In First Out(LIFO) principle. Some operations which can be performed in Stack is : POP (to delete),PUSH( to insert),PEEK (display the top element). A pictoral representation of Stack is shown below: 

![Stack representation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vh50d7pdk5pu7370rumy.png)
_Fact_ : Call logs, Notifications, Browsing History, all these are using stack data structures.

- **Queue** : It is also a type of linear data structure which follow the First In First Out(FIFO) principle. Some operations which can be performed in Queue is : ENQUEUE (to insert),DEQUQE (to delete). A pictoral representation of Queue is shown below: 

![Queue representation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ek7hmwe1fnufex6sb6k.png)
_Fact_ : An Operating System uses queue to function and handle data.

<u>**Non-Linear Data Structures**</u>

In Non-Linear Data Structures, data elements are not arranged in a sequential order. It is a hierarchical way of storing data. Trees and Graphs are examples of this type of data structure.

- **Trees** : It is a non-linear, hierarchical data structure consisting of a set of nodes, where each node contains a data value. Trees do not store data sequentially, thus is easier and faster to store and retrieve data. A pictoral representation of Tree is shown below: 

![Tree representation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5yo39fa6lh9qfjpcx16.png)

Binary tree is a special type of tree where the data value in the node of the left subtree is always less than the root node and the data value in the node of the right subtree is always more than the root node.

_Fact_ : My Files or any types of files on your computer most probably uses trees to maintain data.

- **Graph** : A Graph can be defined as a set of vertices & edges. Vertices are also known as nodes. Edges connect two vertices/nodes.


![Graph representation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/su86xc2qo24ulyia94us.png)
_Fact_ : Companies like Facebook, Google uses graph to store and retrieve data. GPS navigation also uses graph data structure.


_<u>**DISCUSSION**</u>_
Now we have covered a basic description of data structures. As a beginner this information might be a little overwhelming and seem difficult at first but as your practise increases, these seem like cakewalk. What we have discussed so far is very basic information and there is an ocean left to cover. 
In case you are learning data structures in C language, I have a repository for you to refer.(https://github.com/sanjeeban5644/C_Data_Structures.git)

Thankyou for reading! See you in the next blog.

Connect with me : 
Twitter -> https://twitter.com/sanjeeban_5644
Linkedin -> https://www.linkedin.com/in/sanjeeban-mukhopadhyay-4bb4b01b8/