
WHY SHOULD ALL PROGRAMMERS KNOW ABOUT DATA STRUCTURE AND ALGORITHM ?
As a programmer or coder or software engineer,does the words Array, Linked List, Stack, Queues, Searching, Sorting, Tree, Graph etc make your bones rattle with fear and dread ?
Apart from these dreadful feelings,Do you also wonder that why should I study all the above-complicated stuff when it apparently has no use in real life? Why do then companies ask questions related to data structures and algorithms if it’s not useful in a daily job?? In this blog,I would like to address some of these concerns and shed some light into this topic regarding its importance.
A lot of beginners and even experienced coders avoid learning Data Structures and Algorithms because it’s indeed complicated and they think that there is no use of all the above stuff in real life. But before we go further in the topic we are going to throw a simple problem at you and you need to find the solution for that.
If you need to search one particular number in a 40,000 pages of PDF document (numbers are arranged in an increasing order) how would you do that?
- If you will try to search it randomly or in a sequential manner it will take a very very long time. You might get frustrated and tired after some time.
- You can try another solution which is given below…
- Go to page no. 20,000
- If the number you are looking for is not there, but all other numbers in that page are lesser than yours then
- Go to page no. 30,000
- Still if your number is not there.,but this time all other numbers are greater than yours, then
- Go to the page no. 25,000
Continue the same process and within 30-40 seconds you will find the number that you are looking for. Congratulations… you just have used Binary Search algorithm unintentionally..
From the above example, I hope you have realised that how important it is to learn Data Structure and Algorithms.Following are some very important reasons to learn this :
- If you want to crack the interviews and get into the product based companies
- If you love to solve the real-world complex problems.
1) To Crack the Interviews of the Top Product Based Companies
Here is a fun fact for you, all the SQL and Linux commands are basically algorithms and data structures. Not only them,but most software components have lots of algorithms and data structure beneath them and that’s how software works .
Data structures and algorithms play a major role in implementing software. Hence in these top knotch product companies hiring process, often data structures and algorithms play a very critical factor in shortlisting potential candidates . Many students as well as experienced professionals often wonder as to why do these companies’ interviews are always focused on DSA(Data Structures and Algo) instead of language/frameworks/tools specific questions? Let us delve into this topic in more details below…
When you ask someone to make a decision for something the good one will be able to tell you “I chose to do X because it’s better than A, B in these ways. I could have gone with C, but I felt this was a better choice because of this“. In our day-to-day life, we will always go with that person who can complete the task in a short amount of time with efficiency and using fewer resources. The same things happen with these companies. The problem faced by these companies is much harder and at a much larger scale. Hence the Software developers employed in these companies have to make the right decisions when it comes to solving the problems of these companies.
For this purpose,it becomes very important for the software developers to have the knowledge of data structure concepts like Hash Tables, Trees, Graphs, and various algorithms. Having the knowledge of these concepts goes a long way in solving the problems faced by the companies efficiently and the interviewers are more interested in seeing how candidates use these tools to solve a problem. Just like a car mechanic needs the right tool to fix a car and make it run properly, a programmer needs the right tool (here, algorithm and data structure) to make the software run properly. So the interviewer wants to find a candidate who can apply the right set of tools to solve the given problem . If you know the characteristics of one data structure in contrast to another you will be able to make the right decision in choosing the right data structure to solve a problem.
Software Engineers in Google, Microsoft, Facebook, Amazon-like such companies are different than others and paid higher as compared to other companies…but why? Because in these companies coding is just the implementation and roughly takes 20-30% of the time allotted to a project. Most of the time goes into designing things with the best and optimum algorithms to save the company’s resources (servers, computation power, etc). This is the main reason why interviews in these companies are focused on algorithms as they want people who can think out of the box to design algorithms that can save the company thousands of dollars. Youtube, Facebook, Twitter, Instagram all these sites have the highest number of users in the world. To handle more users on these sites it requires more optimisation to be done and that’s the reason product-based companies only hire candidates who can optimize their software as per user demand.
Example: Suppose you are employed in Facebook as a software engineer. You come up with an optimal solution of a problem (like sorting a list of users from India) with a time complexity of O(nLogn) instead of O(n^2) and assume that n for the problem here for the company in real life scenario is 100 million (very fair assumption considering the number of users registered on facebook exceeds 1 billion). nLogn would be 800 million, while n^2 would be 10^7 billion. In cost terms, you can see that the efficiency has been improved more than 10^7 times, which could be a huge saving in terms of server cost and time.
Now you might have got that companies want to hire a smart developer who can make the right decision and save company resources, time and money. So before you give the solution to use a Hash table instead of List to solve a specific problem think about the big scale and all the case scenarios carefully. It can generate revenue for the company or the company can lose a huge amount of money.
2) To Solve Real World Complex Problems
Have you ever been scolded by your parents when you were unable to find your book or clothes in your messed up room? Definitely yes…your parents are right when they give the advice to keep everything in the right place so the next time you can get your stuff easily. Here you need to arrange and keep everything (data) in such a structure that whenever you need to search something you get that easily and as soon as possible. This example gives you a clear idea that how important it is to arrange or structure the data in real life.
Now take the example of a library. If you need to find a book on Set Theory from a library, you will go to the maths section first, then the Set Theory section. If these books are not organized in this manner and just distributed randomly then it will be frustrating to find a specific book. So data structures refer to the way we organize information on our computer. Computer Engineers process and look for the best way we can organize the data we have, so it can be better processed based on the input provided.
A lot of newbie programmers have this question that where we use all the stuff of data structure and algorithm in our daily life and how it’s useful in solving the real-world complex problem. We need to mention that whether you are interested in getting into the top tech giant companies or not DSA still helps a lot in your day to day life. Don’t you believe us…Let’s consider some examples…
- Consider Facebook . Can you just imagine that your friends on facebook, friends of friends, mutual friends they all can be represented easily by Graph? Relax….sit for a couple of moments and think again…you can apply graph to represent friends connection on facebook.
- If you need to keep a deck of cards and arrange it properly how would you do that? You will throw it randomly or you will arrange the cards one over another and form a proper deck. You can use Stack here to make a proper arrangement of cards one over another.
- If you need to search a word in the dictionary, what would be your approach? Do you go page by page or you open some page and if the word is not found you open a page prior/later to one opened depending upon the order of word to the current page (Binary Search).
The first two were a good example of choosing the right data structure for a real-world problem and the third one is a good example of choosing the right algorithm to solve a specific problem in less amount of time.
All the above short examples give you a clear understanding that how the organization of data is really important in our day to day life. Arranging data in a specific structure proves to be really helpful in saving a lot of time and it becomes easier to manipulate or use them. The same goes for the algorithm…we all want to save our time, energy and resources. We all want to choose the best approach to solve the problems in our daily life. A lot of problems exist in the world that can take hours or days to be solved with the native solution, it also may take years ! can you imagine!
Hence to conclude this blog post,Data structure and algorithms help in understanding the nature of the problem at a deeper level and thereby a better understanding of the world.Hence for this reason,it does indeed become very important for all coders/programmers/software developers to be well acquainted with data structures and algorithms.
