what is the difference between O(nk) and O(n+k) in time complexity?

后端 未结 5 1104
北荒
北荒 2021-01-01 03:14

In big O notation of time complexity in algorithmic analysis, when an algorithm depends on n and k, what is the difference between these two notations. Also pls help in the

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 03:45

    O(nk) means the time it takes is proportional to n * k. O(n+k) means the time it takes is proportional to n + k. It's exactly what it seems like. You will need to be more specific in your question about what you don't understand.

    In your case, the algorithm's runtime is O(nk) because the inner loop runs a total of n * k times.

提交回复
热议问题