0
What is the time complexity (Big O notation) of this code?
Hi guys, Need an help with Big O notation.. what is the time complexity of the following code? function question (num) { for(i=1; i <= num; i*=2) { console.log(i); } } I think it is linear so O(n) because also with large inputs the beaviour remains linear, we scan all the array and multiple each element by 2. EDIT: I guess it s wrong because I'm halving the inputs, for example num = 16 -> 1, 2, 4, 8, 16, 32 Actually I'm multiple the indexes ... so it could be logarithmic
1 ответ
+ 4
It is logarithmic.