Re-cap on my BigO studies from the LeetCode DSA course. 👇

Here's my understanding of the topic (please, correct me if I am wrong!). 🥸

BigO is a notation used to describe the computational complexity of an algorithm.

Complexity is usually split into two parts:
Time Complexity: the time the algorithm needs to run, relative to the input size. 

Space Complexity: the amount of memory allocated by the algorithm when run relative to the input size.

We use a function (math formula) to represent BigO notation.

Here's some example functions and their respective time complexity in BigO.

I won't discuss space complexity for brevity of the post, but please follow along and comment if you'd like to discuss it!

getFirstElement has a time complexity of O(1) - we are accessing the first element of an array, which is a single operation (1).

printElements has a time complexity of O(n) Linear Time - the time grows linearly with the input size. 

In this function, we loop through every element of the array (n), so the time taken is also n.

printPairs has a time complexity of O(n^2) Quadratic Time - the number of operations grows with the square of the input size. 

As the outer loop runs n times, the nested inner loop runs n times, so the time complexity can be represented as n * n or simply, n^2. 

binarySearch has a time complexity of O(log n). 

The time grows logarithmically as the input size increases (each iteration cuts the search space in half, making it much faster than linear search). 

Another time complexity is O(2^n) which represents exponential time - common in unoptimised recursive algorithms. 

In this case, time doubles with each additional input. E.G if the input size increases by 1, the number of operations doubles. 

I hope you enjoyed reading this post, and if you got so far, thanks for hopping in! 

Please do comment or share if you like. 🙂