Why Do We Need Data Structure?

Why Do We Need Data Structure?
Photo by Taylor Vick / Unsplash

For every programmer, it is really important to understand the data structure and which one is more suitable for a solution. There could be multiple ways to solve the problem but once you look into the larger scale one can start finding which solution is most suitable for the problem. Here, one can run through the answers of what, why, and how?

What is Data Structure?

In programming storing and managing data in an efficient way.

Why do we need Data Structure?

For example, you have to search for the phone number of your friend on your mobile which contains hundreds of contact numbers. You simply go to the mobile contacts you already saved and search for your friend’s name. If you do the same thing without saving the name of your friend it becomes difficult to find the number. Here you have done two things.

  1. Saving the contact number.
  2. Searching for a particular number.

You are saving the data in a particular format which allows you to do a search for any name quickly. It saves you a lot of time compared to if you wouldn’t have saved the phone number without a name. Without proper data structure, you may lose so much amount time and storage.

How to solve this ?

To choose any particular data structure one has to consider two things about the approach:

  1. Time Complexity - Your solution must be fast enough
  2. Space Complexity - Your solution must consume less space

Various data structures

– Arrays
– Stack
– Queue
– List
– Tree
– Graph
– Merge Sort
– Quick Sort
– Linear Search
– Binary Search

Read more