DEV Community

Cover image for Intro to  Big O Notation 👀

Intro to Big O Notation 👀

Sai gowtham on October 03, 2018

What is Big O? In computer science, big O is used to analyze how their running time or the space used by an algorithm.it is invented by ...
Collapse
 
thiht profile image
Thibaut Rousseau

The last example doesn't look quadratic to me but linear, because the second loop is executed a fixed number of times. Its complexity would be O(10 * n), which is proportional to O(n)

Collapse
 
sait profile image
Sai gowtham

Updated

Collapse
 
malib profile image
Ali

O(10 *n) how ?

Can you explain please !

Collapse
 
thiht profile image
Thibaut Rousseau

The author fixed it, but the code used to be something like:

for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < 10; j++) {
        console.log(arr[i] + arr[j])
    }
}

The console.log statement is executed arr.length * 10 times. That's a complexity of O(10* n), n being the size of the arr array.

Collapse
 
antoinebr profile image
Antoinebr

Looking forward to read the next tuts ! 👍

Collapse
 
sait profile image
Sai gowtham

checkout next tutorial .

Collapse
 
mshel profile image
MikhailShel • Edited

the last example should have
for (var j = 1; j <= n; j++) {
or
for (var j = 1; j <= i; j++) {
for 2'd loop

to be O(n2). That's critical. Any constants in Big O notation can be dropped

Collapse
 
sait profile image
Sai gowtham

Updated

Collapse
 
diek profile image
diek

Ouch, logarithms one were the content I was looking for when I entered here, I hope you will post it soon.

Collapse
 
sait profile image
Sai gowtham

checkout Logarithms

Collapse
 
theoutlander profile image
Nick Karnik • Edited

It would be nice if you could expand a bit on this topic since there's more to it.

The Big-O Cheat Sheet is nice, especially that poster!!