简体   繁体   中英

Algorithm with O(log N^3/M) time complexity

I am trying to write an algorithm with O(log N^3/M) time complexity. However, I am not sure about log N/M part. I'd be grateful if someone could confirm if my algorithm is correct.

for (int i = 1; i < N; i = i*2) // log N
  for (int i = 1; i < N; i = i*2) // log N
    *for (int i = 1; i < N; i += M+i*2) // log N/M

* If for (int i = 1; i < N; i += M) has O(N/M) time complexity, and O(log N) requires i to be multiplied by a constant then the conclusion is that O(log N/M) can be achieved if we add the constant to i and multiply it by another constant at the same time.

What would be an algorithm for O(N/log N) time complexity?

I think that : for (int i = 1; i < N; i += M+i*2) is not O(log(N/M)) because lets say that the loop will run for k times then we have: k*M + 2^k >=N -> which doesn't leads to k=O(log(N/M)).

Instead you could write:

for (int i = 1; i < N/M; i =i*2)

this is obviously O(log(N/M)).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM