Why Data Structures..
Published: 2022-03-28 09:18:42

Data structures are used in computing to make it easy to locate and retrieve information. 

Primitive data structures are simple ways for programming languages to represent basic values. These include data types like integer, char (character), Boolean, pointers, and the like. 

Non-primitive data structures provide ways of storing multiple values in a single variable. These include arrays, linked lists, stacks, graphs, trees etc..

In each case, the way the data is "structured" makes it easy to retrieve or manipulate.

```
- They should be efficient. 
Data structures make programs more productive with regards to time. ...
- They should be reusable.
 Once a data structure is implemented, it needs to demonstrate
 an ability to be used for other, similar data needs. ...
- They should remain hidden.
```

**Types of Data Structure**

Basically, data structures are divided into two categories:
1. - Linear data structure
2. - Non-linear data structure

## **Linear data structures**

In linear data structures, the elements are arranged in sequence one after the other. Since elements are arranged in particular order, they are easy to implement.

Popular linear data structures are:
**_1. Array Data Structure_**

An array is a data structure that contains a group of elements. Typically these elements are all of the same data type, such as an integer or string. Arrays are commonly used in computer programs to organize data so that a related set of values can be easily sorted or searched.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/napmi2dt2yjrhbp89yj8.jpeg)

**_2. Stack Data Structure_**

Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO (Last In First Out) or FILO (First In Last Out). It works just like a pile of plates where the last plate kept on the pile will be removed first. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggpg3gg9lg4tma01uw8j.jpeg)

**_3. Queue Data Structure_**

The queue is a linear data structure used to represent a linear list. It allows insertion of an element to be done at one end and deletion of an element to be performed at the other end

Unlike stack, the queue data structure works in the FIFO principle where first element stored in the queue will be removed first.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljn21z63nxb4d1cvy2w7.jpg)
**_4. Linked List Data Structure_**

A linked list is the most sought-after data structure when it comes to handling dynamic data elements. A linked list consists of a data element known as a node. And each node consists of two fields: one field has data, and in the second field, the node has an address that keeps a reference to the next node. Each node contains the data items and address to the next node.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuww3snf8ajwvakxziux.jpg)

## **Non linear data structures**

Unlike linear data structures, elements in non-linear data structures are not in any sequence. Instead they are arranged in a hierarchical manner where one element will be connected to one or more elements.

**_1. Graph Data Structure_**

Graphs in data structures are used to address real-world problems in which it represents the problem area as a network like telephone networks, circuit networks, and social networks. For example, it can represent a single user as nodes or vertices in a telephone network, while the link between them via telephone represents edges.

In graph data structure, each node is called vertex and each vertex is connected to other vertices through edges.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axrij13yy5p6e5hcdxis.jpg)

**_2. Trees Data Structure_**

Among various real-world applications, the tree data structure is used to demonstrate relationships between different nodes with the parent-child hierarchy. It is also called a hierarchic data structure because of this. It is most popular for simplifying and speeding up searching and sorting.
Similar to a graph, a tree is also a collection of vertices and edges. However, in tree data structure, there can only be one edge between two vertices.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qj1y9jy40icpe7abshaw.jpg)