This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Big O Forum

View Course » View Exercise

2533 points
Picture
Submitted by
Edwin Kwong
over 4 years ago

Anyone figured this out yet?

Doesn't make sense to me at all :(


1 vote

permalink

The answer is

console.log("O(n)");

Still have no grasp on BigO =/

2533 points
Picture
Submitted by
Edwin Kwong
over 4 years ago

5 Comments

522dd491548c3524d800aa71_105604173 wwayne over 4 years ago

have no grasp on it too...

4f8f6ea95a87fe00030031ad_732049700 Eric Summers over 4 years ago

Big O is a description of how much work an algorithm has to do compared to the size of the input you give it. Try reviewing section 2 of this course keeping that in mind.

5501ec9995e37864d90041c6_256957753 Miki over 4 years ago

This one is a bit harder than U think Eric...

4fee1853814eff000303dd3f_68456947 Byron Smith over 4 years ago

Yes, this subject needs to be explained a LOT better for people who are not professional coders to understand. Telling us to review a section that didn't explain things clearly isn't really going to help.

533b22568c1ccc6c0d00409e_910858883 Sofia Perwallius about 3 years ago

Thanks


0 votes

permalink

Here is a dirty way to figure out the "O"....
insert a different counter in each loop...
I used   f,g and h counters;

and then find the largest numbered loop.
After comparing the largest loop with the input number I can calculate the "O".
--------------------------

var f = 1;
var g = 1;
var h = 1;
var printer = function(n){
    for(var i = 0; i < n-2; i++){
        console.log (f++);
        console.log("Warming up printer...");
    }
    var sum = 0;
    for(var j = 0; j < n/2; j++){
        console.log (g++);
        sum += j;
    }
    for(var k = 0; k < n; k++){
        console.log (h++);
        console.log("The sum is: " + sum);
    }
};

printer(5);
console.log("O(n)");

----------------------
(The printout a maximum of 5 loops)

1
Warming up printer...
2
Warming up printer...
3
Warming up printer...
1
2
3
1
The sum is: 3
2
The sum is: 3
3
The sum is: 3
4
The sum is: 3
5
The sum is: 3
O(n)

------------------------------

2198 points
561615eaafcf6921ce4288271566d49f?s=140&d=retro
Submitted by
kvkeller
over 4 years ago