How to Prepare Data Structure and Algorithms for Machine Learning and Data Science Interview.

If you are a machine learning engineer or working in the data science domain, Data Structure, and Algorithm is a must-have skill. I have talked to many people, and they are always confused about how to learn data structure and algorithms to crack machine learning interview. Here in this post, we will discuss what you should do and what not to get a good grasp over data structure and algorithms, and how you can acquire DSA skills within just 25-30 days.

Key Points:
  1. How to start.
  1. What resources to follow.
  1. How to practice.

If you are a beginner, learn any programming language and get a good grasp over it. During this phase, you can practice using fundamental programming problems. If you are already pro in any programming language, you can skip this step. In this phase try to solve the following set of problems

  1. Write a program to add, subtract, multiply, divide two numbers.
  2. Write a program to check if two numbers are even or odd.
  3. Write a program to check whether a number is prime or not.
  4. Write a program to calculate the nth Fibonacci number.
  5. Write a program to calculate the number of words in the sentence.
  6. Write a program to reverse a string.
  7. Write a program to remove all the duplicate values from a list/array.
  8. Write a program to add two 2-D metrics without using the inbuilt function.
  9. Write a program to multiply two 2-D metrics without using the inbuilt function.
  10. Write a program to convert decimal numbers to binary and vice-versa.
As you have completed all the above questions, now you will be comfortable with the syntax of that programming language (Try to solve more fundamental problems, it will boost your confidence). Now you can start learning data structure. Here in this article, We will talk about mainly five data structures:

  1. Linked List
  2. Queue
  3. Stack
  4. Tree
  5. Hash Map

Pick each topic one by one and see some videos over youtube (make a youtube search and see first 2-3 videos on each section). It will help you in developing an intuitive understanding of that particular data structure and how it works. 

Till this point, you will be clear about how a particular data structure works, and what is the syntax to implement that data structure.
Now you have to open https://www.geeksforgeeks.org and search for each data structure. In each of the sections (Linkedin List, Queue, Stack, Tree, Hash Map), you have to solve only ten questions. I am assuming that you can solve ten problems within one day. So to complete 50 questions, it should take five days at max. One thing to remember, you have to code all the problems from scratch. You can take help from the solution given on GeeksforGeeks, but don’t just copy-paste the code. 

  1. Linked List 
  2. Queue
  3. Stack
  4. Tree
  5. Hash Map
Now again, repeat this cycle, but this time solve only five questions per day from each topic and do this until you solve 30 problems from each section. When you solve these 150 questions from all the topics, you will come to know that at least half of the problems are duplicate. You can also put solutions to these problems on your GitHub. 
After doing this, you need not code every problem. Now, you have to read some problems and try to code that using pen & paper.

Algorithm: 


In the algorithm section, we are going to learn four kinds of problems only. 
  1. General Array problems
  2. Greedy problems
  3. Graph related problems
  4. Dynamic programming problems

Before solving algorithm problems, first, we will learn about the complexity analysis of any problem. You will get a clear understanding of the complexity analysis of any algorithm just by looking at these two videos:


Now you are ready to work upon your algorithm part. Unlike data structure, here, we will follow a different path. As dynamic programming problems are the most difficult ones to solve, so we will address them in the later part of our learning process. 

We will start by solving the first 30 problems from the array section. All these will mostly be standard problems, and you have to code them from scratch. Now you have to solve 20 problems from the Greedy section and ten from the graph section. At this point, you can get relax, but you don’t have to break your rhythm, take one or two days, and solve ten standard dynamic programming problems.  

Once you are done with all the above steps, I will highly recommend you to buy a book named Coding Interview Questions. It is a must-read book for any computer science student. It contains a beautiful set of problems. Once you are done with this book, go for cracking the coding interview book. It contains questions from different areas of computer science, such as databases, operating systems, data structure, computer networking, etc. 

Now you can go to any interview very confidently. I can bet, in any interview, you will be asked only the problems that you have already solved, or very similar to that. 

You can join our telegram group for data structure and algorithm preparation: Data Structure and Algorithm Telegram