How to Figure Out the Least Time Complexity

Noah
1 min readMay 27, 2021

When you try to solve algorithms and data structure problems, it’s not like just “solving”, but also there are a lot of things to think such as time complexity, space complexity, readability and so on.

One of the important thing of them is imagine what’s the least time complexity of the problem.

The way to imagine the least time complexity is to imagine how many times you have to check the each element at least.

Let’s say you are trying to solve the very easy problem which is to make a function returning true if the array’s all elements which is supplied as argument are same.

In this problem, you have to check all the elements in the array once at least. So it means it’s impossible to make the time complexity less than O(n). Which means you can imagine you may solve the problem with O(n).

After imagining that, you can focus on thinking up the way to solve as the least time complexity.

If you feel it hard to figure out the least time complexity, please try to do as this way is.

--

--