The 5 most important Algorithms for a DSA Interview
If you are preparing for an upcoming interview or if you are catering resources for interview preparation then this article would be of great help to you. I am going to discuss the 5 most important algorithms for a DSA interview at top product-based companies.
I have solved 550+ questions myself, have given some interviews, and also done a good amount of research. So after doing all this, I have come up with a list of 5 algorithms that you must practice to increase the chances of success in your tech interview.
The first algorithm would be Dynamic programming. It wasn't so hard to guess, was it? Dynamic Programming is probably everyone's nightmare. It is quite tough to understand it but once you start solving DP questions regularly, you will notice some patterns.
If you are a beginner, then my advice would be to master recursion first. Understand it as much as you can. Understanding recursion is the key to becoming a very good DP, Trees, Graphs problem solver. If you get the hang of recursion, dynamic programming would become a lot easier for you.
There are tons of great DP questions on websites like Leetcode and Hackerrank. I am not including CP sites here in the article.
Go check this out for a great DP guide.
0/1 BFS. Breadth-First Search is a traversal technique used to traverse in graphs. 0/1 BFS is a technique to traverse a graph in such a way that you reach a particular point in a given minimum time or minimum cost. Well, the problems under this category look solvable via DFS but in a majority of the problems, you will get a TLE or it will fail in some cases.
0/1 BFS algorithm questions are really good-level questions. One of the best ways to master 0/1 BFS questions is to solve shortest-path/ shortest-time in trees, graphs. There are a few famous 0/1 BFS questions that are asked regularly in interviews like the number of oranges, dungeon game, etc.
Go check this out for a great Graphs guide.
Binary Search. Well, if someone asks you an unseen binary search question in an interview and you are able to answer it without any help in the first attempt, then you don't need to read this article I guess.
Binary Search is not only about sorted arrays. Binary Search can be applied anywhere where you see a sorted range. One of the most popular ways to apply Binary Search is to do a Binary Search on the answer range. Try this question to understand what I mean by the above statement.
Try all the variations of Binary Search. Practice 4-5 questions on each variation and then you will be confident that you can recognize a Binary Search pattern now.
Go check this out for a great Binary Search guide.
Two-pointers. Two-pointers is a beginner's level concept but there are a lot of varieties to it. Slow fast pointers, start-end pointers, and sliding windows are some of them. In most problems, Two pointers algorithm is the most optimized way to solve the problem. One of the examples of such question is the Trapping Rainwater problem
If you have practiced a few questions on all the varieties of the two-pointers algorithm then you are already ahead in the interview preparation.
DFS. DFS is called Depth First Search. It is also a way to traverse graphs and trees. One variation of DFS that is a very popular interview algorithm is topological sorting. Topological sorting is basically sorting the nodes in the order of their visits.
There are a lot of problems that can be solved by both DFS and BFS. So it is highly recommended to study both algorithms before any tech interview.
Go check this out for a great Graphs guide.
You can agree with me or you cannot. It is completely up to you. Every algorithm is important and you must have a basic idea about all of them but these 5 are probably the most important ones(according to me). One algorithm which could have made the list instead of DFS is Bit Manipulation.
It is another topic which a lot of beginners fear. It is tricky and it does not come intuitively. Practice a lot on bit manipulation. Understand the basics and ONE FINE DAY you will be able to understand what's happening. If you want a list of good questions on such topics, then follow these threads.
Go check this out for a great Bit Manipulation guide.
So this concludes the article on the 5 most important algorithms for a DSA interview. If you think this article helped you or made you aware of new things, then consider sharing it with your friends.
Follow CSwithIyush for more tutorials & tips/tricks on Flutter & DSA.