DEV Community

Discussion on: Intro to Big O Notation 👀

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.