Data structures and Algorithms are complicated and it takes time to become familiar with them. There are moments when we are stuck and often ask why we are studying these complex topics that are irrelevant, or of no use, especially while solving problems. Thus in this blog, we will see the importance and real-life uses of data structures and algorithms.
The data structure is simply a container where we can store data in some ordered fashion. In other words, the data structure is a way of storing data in computers in an organized manner such that data retrieval and updating are efficient.
Programming as we explore, we realize that many concepts are inspired by real life itself. Similarly, the majority of the data structures are also derived from real-life scenarios.
- Say for example 2D array is much like a matrix and we can perform almost all the matrix calculations with the help of a 2D array.
- Usernames in social media that uniquely identifies the user are just like HashMap where each key uniquely identifies the value associated with the key.
- The queue data structure is identical to the queue of people standing and waiting for their turn at a ticket counter. The people arriving first get their tickets first, in the same way, processing arriving first is executed first.
- The stack data structure can be related to the stack of plates, we can only access the plate at the top, to access other plates we are required to remove the plates above it.
In our daily lives, we come across a lot many data structures without even knowing it. From our way of organizing books on the shelf, a contact list to store various contact details, understanding your relationship with your cousin using family hierarchy, and creating a to-do list, we are applying different arrangement techniques which are known as data structures in the world of computers.
An algorithm is simply a set of instructions that are to be performed in order to fulfill a certain task or get the desired result. Let us say we want to prepare tea and we ask our mother for the instructions. She replies as follows:
- Take half a cup of water in a pan and boil it.
- Put 1 1/2 tsp of tea leaves, 1 1/2 tsp sugar, 1/4 tsp tea masala, and one cup milk.
- Steep the tea for at least 5 minutes
- Pour it into a cup.
This is nothing but an algorithm to make tea. There are various procedures stored inside computers that help them come up with solutions to perform various actions. Algorithms are well-defined, step-by-step procedures that help computers solve problems. Major categories of algorithms include searching, sorting insertion, updation, deletion, etc.
Another example of algorithms in day-to-day life is how we look for a word in a dictionary. We first open some random page. Say we are looking for the word "question", this random page opened contains words starting with
r so we will for the word in the previous section of the dictionary. Again, we choose a random page it contains the word "Quartz". Thus, we know that our word lies after this word on the current page and before the previous random page. This is a Binary search algorithm that is used to search for elements from a sorted group of elements.
We can conclude that many of the algorithms are also inspired by how we perform tasks in real life.
Why do we need to learn data structures?
1. To crack Interviews
You may question, why product-based companies focus on the DSA skills of the applicant?
First of all, Data structures and algorithms are used everywhere, say from our morning alarms, washing machine, fridge, and other devices, in mobile phones, we resent apps are also stored in data structures and the friend suggestions we see on social media apps are algorithms designed in an accurate and efficient way. In a way using algorithms we are telling computers, how to make choices.
There are two valuable resources that are considered while solving a problem. These are time and space. Time taken to solve a given problem and space used to store the data. All the data structures and algorithms are the tools and the interviewer is curious to see how efficiently we use them to complete the tasks in the minimum amount of time and by using fewer resources.
Software engineers in most of these product-based companies spend a very little amount of time implementing code and most of their time designing a solution to complex problems. Their major task is to give potential and the best algorithms to save companies' resources. These algorithms are to be designed in such a way that they give optimal results even in the future when the company might have more data to handle i.e. they should be scalable. Thus, these companies want their employees to think out of the box to design algorithms that give accurate results and also save thousands of dollars for the company.
Imagine that the algorithm initially working say
algo1 uses n2 space and you with your team come up with a solution i.e.
algo2 that can work with
n(log n) space. Now we have the number of data items that is
n which is equal to
10,000 (ten thousand). Thus, if we calculate the space required by both these algorithms is 100,000,000 for the
algo1 and 40,000 for
algo2. The actual company has data in millions and billions and thus the difference between these two complexities even increases. As a company, this is a huge difference and you can save so much memory space and storage costs for the company.
Thus, companies want to hire intellectuals as they have problem-solving skills as well as they are assets to the company. As a developer, it is very important to make the right decisions, these decisions save a lot of resources, money, and time for the company.
Also, companies require a common ground on basis of which they can hire people with various different skills. In an interview each person has a different set of skills and a multinational company require people with all these skills. Hence, rather than dividing people into different small groups, they take a common DSA test. This makes sense as a hardworking person can learn new skills in no time and be useful to the company.
2. To solve some real-world complex problems
We are often asked to be organized and disciplined. This is because, when we are organized from the beginning, we save a lot of our time in sorting things as well as it is easier to find things when required. Similarly, in the library books are kept in sections and in order so that books are easily accessible. It is the same with the data kept in computers, it is organized such that when the user looks for some file user gets it as soon as possible. The user might not be looking for some file directly but he/she may be using some application that requires data from that file. Computer scientists believe that the better the way data is organized the better it can be processed based on the input provided.
Learning about data structures and algorithms not only improves our problem-solving skills in terms of software designing but also in solving real-life problems. We tend to look at all the possible solutions, make a choice out of all the options, calculate the efficiency, analyze it in-depth, and then come up with solutions that are meaningful.
The technology that we use today is going to become better day by day in terms of speed, accuracy, etc. where data structures and algorithms are extensively used. Any new technology that will be coming up will also require these skills along with new skills. Using data structures and algorithms we can reduce space requirements and time to process the data. These solutions must be optimized and scalable so that they are effective in the future as well. It also develops critical thinking for all types of problems and we learn to take a wider look at real-life problems and problems that we face as an engineer. DSA is very important for all budding programmers who wish to succeed in their computer science careers.