Time and Space complexity of an Algorithm — simplified with examples

--

Hello everyone. In this article, we are going to look at one of the complicated and terrifying topics i.e computing the Run Time and Space complexity of an algorithm. Most of the programmers find it hard and also struggle in the interviews due to this.

I have kept the theory part minimum and explained things simpler with diagrams and examples and I am sure you will understand the time / space complexity easily after reading this. Let's get started

Big(O) Notation

Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity.

We use this Big O notation to describe the performance of a given algorithm. With the notation, we can find if the particular algorithm can scale up with the increased input.

Let us see how we calculate the Big 0 notation for the algorithms

Basically, this asymptotic notation is used to measure and compare the worst-case scenarios of algorithms theoretically. For any algorithm, the Big-O analysis should be straightforward as long as we correctly identify the operations that are dependent on n, the input size. we have to remove all the constant factors.

--

--

Dineshchandgr - A Top writer in Technology
Javarevisited

Principal Software Engineer and Technical Lead focussed on Backend Engineering who likes to upgrade the tech skills and share knowledge to the community