Big O Practice

Run Settings
LanguageJavaScript
Language Version
Run Command
// worst case const boxes = [0,1,2,3,4,5]; function logFirstTwoBoxes(boxes) { console.log(boxes[0]); // 0(1) console.log(boxes[1]); // 0(2) } logFirstTwoBoxes(boxes) // 0(2)
// What is the Big O of the below function? (Hint, you may want to go line by line) function anotherFunChallenge(input) { let a = 5; // O(1) let b = 10; // O(1) let c = 50; // O(1) for (let i = 0; i < input; i++) { // O(n) let x = i + 1; // O(n) let y = i + 2; // O(n) let z = i + 3; // O(n) } for (let j = 0; j < input; j++) { // O(n) let p = j * 2; // O(n) let q = j * 2; // O(n) } let whoAmI = "I don't know"; // O(1) } // Big O = 4 + 7n = O(n) // O(n) - n means it's a variable which it depends on the number of inputs for the loop // O(1) - 1 means we have the value and that value is 1 process in that line of code
// What is the Big O of the below function? (Hint, you may want to go line by line) function funChallenge(input) { let a = 10; // O(1) a = 50 + 3; // O(1) for (let i = 0; i < input.length; i++) { // O(n) - n is input anotherFunction(); //O(n) let stranger = true; //O(n) a++; // means a+1 O(n) } return a; // O(1) } // BIG O(3 + 4n) simplifie to O(n)
Editor Settings
Theme
Key bindings
Full width
Lines