Is n or nlog(n) better than constant or logarithmic time?

前端 未结 8 1678
悲哀的现实
悲哀的现实 2021-02-01 07:28

In the Princeton tutorial on Coursera the lecturer explains the common order-of-growth functions that are encountered. He says that linear and linearithmic running times are \"w

8条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 08:05

    constant time is always better because the time (or space) complexity doesn't depend on the problem size... isn't it a great feature? :-)

    then we have O(N) and then Nlog(N)

    did you know? problems with constant time complexity exist!

    e.g.

    let A[N] be an array of N integer values, with N > 3. Find and algorithm to tell if the sum of the first three elements is positive or negative.

提交回复
热议问题