Skip to content

Instantly share code, notes, and snippets.

@arrbxr
Created December 23, 2018 18:02
Show Gist options
  • Save arrbxr/94cf2199d6ea8d38ceb10a0f0561dfe2 to your computer and use it in GitHub Desktop.
Save arrbxr/94cf2199d6ea8d38ceb10a0f0561dfe2 to your computer and use it in GitHub Desktop.
BigO Exercise 1 created by arrbxr - https://repl.it/@arrbxr/BigO-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)
a = 50 + 3; // O(1)
for (let i = 0; i < input.length; i++) { // O(n) here n -> number of input
anotherFunction(); // O(n)
let stranger = true; // O(n)
a++; // O(n)
}
return a; // O(1)
}
// So here big o notaion is
// 3 + n + n + n + n
// BIG O(3 + 4n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment