I am going through algorithms now and I've faced one example where I answered as an Infinite loop
but in the correct answers, it says it's O(log2n)
.
function someFunc(n) {
for(var i = 0; i < n; i * 2) { // I think that Infinite loop cannot be O(log2n), can it?
console.log(i);
}
}
I am a bit puzzled here. I don't understand why because it's the same as the Infinite loop
below, no?
function loop(n) {
while(true) {
console.log(n)
}
}
Source: Sammie Bae - JavaScript Data Structures and Algorithms - 2019 (Chapter 1)