Big O Notation-what is this thing?

What is Big O notation?

const numbers = [4, 7, 9, 10, 25, 46, 15]/ * If we traverse through the numbers in this array to find

4 - The number 4 is at the beginning of the array. It takes least number of operations and the complexity will be measured in Omega(Ω), which is the best case.
10 - To find 10 you need to keep moving till the middle of the array and the complexity will be measured in Theta (θ), which is an average case.15 - For 15, it would take maximum number of operations as we need to traverse all the elements before reaching to find it. This will be worst case which is Omicron(O) or Big O.* /
Time complexity

Time Complexity

Code 1function a() {// Does some operation in 25 secs}Code 2function b() {// Does same operation as function a() in 10 secs}

Space Complexity

space complexity

1. O(n)

Example for Big O(n)
Big O(n)

2. O(n²)

Example of Big O (n²) notation.
Big O(n²)

3. O(1)

function c(add) {return add + add // here the number of operation is 1}
Example of Big O(1)

4. Big O (log n)

Example of Big O(log n)

Note:

Example of Big O(n) with dropping constants
Example of Big O(n²) with dropping non dominants
Summing up Big O

Resources:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store