# Why do we need Data Structures?

Created October 30, 2021

Imagine that you've been eyeing a book for sometime and you wanna buy it. You try to look it up on Amazon.com but without a search option. No wonder how tedious it would be to find it without a search option! Exhausted just by the thought of it, you decide to go to the local library, only to find that all the books are randomly placed on the shelves. It might take you hours to find the book now! This is why Data Structures and Algorithms are important. Data Structures and Algorithms helps in keeping things in a certain order and makes our task easier. In this article I'm gonna walk you through some very fascinating and important Data Structures that might make your tasks simpler and efficient.

## What are Data Structures?

Data Structure is just a way of organizing the data in a certain order. It helps in making the code look simpler, and the task can be done easily in an efficient manner. It also reduces the time complexity of algorithms.

## Types of Data Structures

There are many important Data Structures that you can learn about. But there are some Data Structures that are necessary to be used while you're coding. Following are some important ones:

### Arrays

It is a collection of items of the same data type. Each item has an index number assigned to it in ascending order. You can access items of an array by the index value of that element. Visually, an array looks like this -

It serves somewhat the same purpose as that of arrays. Although it is a bit more complicated to implement as compared to arrays, the time complexity of operations(like insertion, deletion, traversal) is same or lower than that of arrays. You can read more about Linked Lists here. Linked Lists visually look something like this - Above is a visual representation of insertion in a Linked List.

### Stacks

It is a concept that can be implemented on Linear data structures like Arrays and Linked lists. Insertions and deletions happen from only one end and so it follows Last In First Out(LIFO) rule. You can learn more on it (here)[https://devdojo.com/algonoob/stacks].

### Queues

It is a concept similar to stack, the only difference is - operations can happen from both ends in it and so it follows First In First Out(FIFO) rule. Here's how you can implement it in C.

The above data structures are all Linear Data Structures. Queues and Stacks are considered to be Abstract Data Types or ADTs as you can implement them in any language in any way, there are no predefined rules to implement them.

Following are some Non-Linear Data Structures:

### Trees

Items in a tree are divided in various levels in an ordered way. There are rules for traversal, insertion and deletion of elements in it. The Tree data structure literally looks like an inverted tree. It is also an ADT. You can read more about it here.

### Graphs

It contains a set of vertices and a set of edges. The set of vertices are connected to one another through the set of Edges. It is also an ADT and uses various traversal, insertion and deletion methods. Visually it looks something like this -

So, these are some basic Data Structures that makes many algorithms like searching, sorting, Divide and Conquer strategies and so on. They're easy to implement and reduce the time complexities.

## Conclusion

I hope you got an overview about these data structures. You can read more such articles here. Thanks for reading!