The Complete Guide To Understanding Time and Space Complexity of Algorithms

This topic is super trendy in interviews, so you should know it if you are looking for a job

Published in 15 min read Apr 29, 2021

There’s more than one way to solve a problem, but not all of them are the best. Not every solution is capable of efficiently using our resources. Therefore we need to find the best, most efficient solution to a problem before taking action.

In programming, we can’t leave the mechanism of finding the best solution, the best algorithm, to guesswork. We need a clear standard to evaluate the efficiency of solutions. This is where the concepts of time and space complexity step in. They help us determine the algorithm’s efficiency based on the required resources.

In this article, we are going to talk about the concepts of time and space complexity and how we can use them to select the most efficient algorithm for a given task. And of course, this is where notations like O(n) and O(logn), which may have baffled you while learning algorithms, come from.

Efficiency of Algorithms

We measure an algorithm’s efficiency using the time and space (memory) it takes for execution. Time is important because we need our programs to run as fast as possible to deliver…