function funChallenge(input) {
let a = 10; // consttime
a = 50 + 3; // consttime
for (let i = 0; i < input.length; i++) { // lineartime(input.length)
anotherFunction(); // ??? well I would say it depends
let stranger = true; // consttime
a++; // consttime
}
return a; // consttime
}
Considering that the only critical part of the Big O analysis for this code is the loop, I would say that this functions runs in linear time O(n), n being the size of the input array. However I’m not so sure how to analyse the anotherFunction() since I have no clue what it does. I guess I could add its own Big O time? Like O(funChallenge) = O(n*O(anotherFunction()))
So final answer:
Correct answer:
O(n)
My answer is not exactly wrong given my reasoning, but there is a misuse of notation here. Since Big O is already upper bound, there is no need to use the nested O(anotherFunction), it can be just:
, where T = time complexity of anotherFunction()