Why Data Structures and Algorithms for Machine Learning?

Machine Learning and Data Structures & Algorithms are the two most popular concepts in the computer science domain. In Machine learning, we provide an additional ability to our machines to learn patterns from historical data. While on the other hand, Data-Structures are the concept used to store data efficiently, and algorithms around them allow us to write efficient and optimized computer programs.

While interviewing many aspirants for the deep-learning and machine learning domain, we figured out that many of the interviewees think that DS Algo is not required in Machine Learning interviews.

In this article, we will try to give the 5 most important reasons that justify the need for knowledge of DS Algo in the field of Data Science & Machine Learning or Deep-Learning.

1. Real-time prediction is required 

If real systems did not perform in real-time, the outcome would be disastrous; hence, industries exploring Machine Learning technology are highly concerned about ML algorithms' real-time performance. For example, suppose you are solving a problem of object detection using machine learning algorithms. 
For real-time performance, let’s say 15 Frames of images should be executed every second, i.e., 15 FPS, but your algorithm gives you only 10 FPS. Because of that, prediction can be seen as laggy, which is a bad user or customer experience. 
Algorithms written with the knowledge of computational cost can increase your ML algorithm's performance from 10 FPS to 15 FPS, which will make your object detection algorithm work in real-time.

Lag in real world

Credit: Tenor

2. Industries working on real machines demand IoT-device deployable ML algorithms

Edge devices like Arduino and raspberry-pi are widely used IoT (Internet of things ) devices to integrate our code with real systems or machines. Because of the auspicious nature of ML algorithms, industries are leaning towards this technology. But most of the solutions are very heavy to be deployed on any edge device. There are various companies like Facebook, Google, Deeplite that are actually working to reduce ML algorithms' complexity. Knowledge of DS Algo allows you to write such efficient code that can easily be deployed on IoT devices. and become helpful in machine learning production.

IoT chips

Credit: IoTDesign Pro

3. There may be cases where libraries may be unavailable or unable to solve your problem

While working on the real problem statements, there may be situations where you will find that none of the libraries are helping you out with your problem statement. 
For example, suppose there is one problem statement where there are two matrices, and we have to find the product of these matrices. But if the product of two elements in that matrix multiplication crosses a certain defined threshold value, we have to terminate the process and discard those matrix pairs. 

One possibility is to use pre-existing libraries and then perform complete matrix multiplication and then compare the new matrix entries with the threshold value. But if two-parent matrices will be big, it will possibly take higher computation. 
Another possibility is to use your DS Algo knowledge and implement a matrix multiplication solution having the least time complexity. Thus, it will save a huge amount of computational cost. 

Another example can also be related to IoT devices. Suppose you want to deploy your code where you have used one signal filtering library, say Scipy. Being a library, scipy contains several other functions also, and as a consequence, it is taking large space on your edge device, and you can not afford that much space for just one library. Then, in that case, you can also build an optimal algorithm that will not need the parent library.

4. It is important to know how ML Algorithms work

Many machine learning learners think that they can treat ML algorithms as a black box. Feed input data to algorithms, and it will magically produce the output. 
This is not the case with initial learners only. One can easily find such professionals working in the Machine Learning industries who actually have mastered the art of using various algorithms for different problem statements. 
But, what if we need some non-conventional approach to solve any new problem?
People considering ML/DL a black box will find it very difficult to solve in such scenarios. Hence, we always encourage the learning of the WHY of everything. Knowledge of "How ML algorithms work?" It gives us control over it and gives us the additional advantage of inventing something new around that.
To know the principles behind the working of these algorithms, DS and Algo knowledge is a must. For example, one famous ML algorithm, Decision Tree, can be explained using the binary tree, and we learn everything about binary tree in Data Structures and Algorithms.

Decision tree example

5. Algorithmic thinking shows the strength of problem-solving skill

Interviewees love to ask DS algo concepts for any computer science-related role. This is not an exception in the field of Machine Learning. Of course, knowledge of algorithms shows that you have an additional skill, but it shows that you think around any problem and provide the best optimal solution. In addition, it shows your strength of problem-solving skills. So this can give you an added advantage if you appear or plan-to-appear in a machine learning interview.

Out of the box candidate

Credit: Asco Connection

There may be several other reasons that you can find somewhere, but we tried to give you some real-life examples where we actually need the knowledge of Data Structures & Algorithm in this article. 


This article discussed some of the most prominent reasons and areas where Machine Learning and data science require a good understanding of Data structures and algorithms. Most of these reasons are based on the practical experience and the problems faced by ML engineers within several industries. We also have provided some practical examples to justify the reason for this requirement.

Enjoy Learning! Enjoy Algorithm!

We welcome your comments

Subscribe Our Newsletter

Get well-designed application and interview centirc content on ds-algorithms, machine learning, system design and oops. Content will be delivered weekly.