Big O exercise

Run Settings
LanguageJavaScript
Language Version
Run Command
// exercise 1 // 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) because only running once when we run funChallenge a = 50 + 3; // O(1) because only running once when we run funChallenge for (let i = 0; i < input.length; i++) { // O(n) loops are linear time anotherFunction(); // O(n) calling to another function outside of the funChallenge let stranger = True; // O(n) this runs as many times as this loop happens a++; // O(n) a + 1 } return a; // O(1) only once runs } // Big O(n) // exercise 2 // What is the Big O of the below function (Hint, you may want to go line by line) function anotherFunChallenge(input) { let x = 5; // O(1) let y = 25; // O(1) let z = 50; // O(1) for (let i = 0; i < input; i++) { // O(n) let a = i + 1; // O(n) let b = i + 2; // O(n) let c = 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)
Editor Settings
Theme
Key bindings
Full width
Lines