test = 0
for i in range(n):
for j in range(n):
test = test + i * j
*********** B *********
test = 0
for i in range(n):
test = test + 1
***********ç*********
for j in range(n):
test = test – 1
i = n
while i > 0:
k = 2 + 2
i = i // 2
对于A,我认为它是O(N ^ 2),因为嵌套的for循环,对于B,它是O(N),因为它是单个for循环。对于C,我猜它是O(n * log(n)),因为它是for循环和while循环。我假设这是正确的吗?
答案 0 :(得分:2)
你一直到最后一个,因为循环不是嵌套的O(n + log(n))
而且n > log(n)
它只是O(n)