Skip to content

Instantly share code, notes, and snippets.

@arrbxr
Created December 23, 2018 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arrbxr/8ff4091427c55917e9aed318553e55e1 to your computer and use it in GitHub Desktop.
Save arrbxr/8ff4091427c55917e9aed318553e55e1 to your computer and use it in GitHub Desktop.
BigO Exercise 2 created by arrbxr - https://repl.it/@arrbxr/BigO-Exercise-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++) {
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++) {
let p = j * 2; // O(n)
let q = j * 2; // O(n)
}
let whoAmI = "I don't know"; // O(1)
}
// so, BIG O(4 + 5n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment