As a beginner, many developers and students struggle to understand the Big O notation in algorithms to analyze space time complexities. In this article we are going to simply the concept for you.
What is Big O Notnation?
Big O notation is one of the asymptotic way to analyse the performance of an algorithm in terms of time and space complexities. It specifically measure worst-case scenario for space or time requirements of an algorithm as the input size increases. It’s like measuring how much memory it utilise and how much longer it takes to do something when you have more data. This helps us to understand scalability of an algorithm as the input grows.
Big O notation provides an upper bound on the time complexity of an algorithm and focuses on the most significant factors influencing growth rates while ignoring constant factors and lower-order terms. This helps to understand how the algorithm will perform in the long run, regardless of machine or hardware specifics.
Calculating efficiency in Upper Bound is a way to say “at worst, this algorithm will perform this poorly”.
Why Big O notation?
·        Understanding Big O notation allow developers to predicts the scalability of their algorithm even without running the code.
·        Helps developers to choose the most efficient algorithm for their problem, especially when dealing with large datasets.
Common Big O Notations
- O(1) – This indicates Constant Time i.e the algorithm takes a constant amount of time regardless of the input size. For example, accessing a specific element in an array takes the same time no matter how large the array is.
- O(n) – This indicates Linear Time i.e the time taken to execute an algorithm grows linearly with the input size. For example, a loop that iterates through each element of a list once is O(n), where n is the number of elements in the list.
- O(log n) – This indicates Logarithmic Time i.e the execution time  grows logarithmically as the input size grows. Algorithms like binary search have a logarithmic time complexity because they halve the input size in each step.
- O(n^2) – This indicates Quadratic Time i.e the time taken grows quadratically with the input size. This is typical for algorithms with nested loops, like bubble sort, where each element is compared with every other element.
- O(2^n) – This indicates Exponential Time i.e The time taken doubles with each additional element in the input. This is very inefficient and is typically associated with algorithms that solve complex problems, like certain recursive algorithms without optimization.
- O (n!) – This indicates Factorial time i.e the time taken to execute an grows factorially with the input size. This is extremely slow and usually impractical for large inputs. Algorithms that involve generating all permutations of a set, like brute-force solutions to the Traveling Salesman Problem.



