我需要确定这个短代码的大O:
var iterations = 0;
function operation(num){
iterations++;
if (num == 0) return 1;
return operation(Math.floor((num / 10) * 2));
}
var result = operation(1000);
alert('Result = ' + result + ', number of iterations = ' + iterations);
我想出了O(log(logN))
左右的东西,但我不确定。你能帮我一点吗?
答案 0 :(得分:3)
[评论回答]
~log5(N)
次迭代,而是O(log(N))