What is the difference between Θ(n) and O(n)?

后端 未结 9 1230

Sometimes I see Θ(n) with the strange Θ symbol with something in the middle of it, and sometimes just O(n). Is it just laziness of typing because nobody knows how to type th

9条回答
  •  情书的邮戳
    2020-11-22 04:47

    Rather than provide a theoretical definition, which are beautifully summarized here already, I'll give a simple example:

    Assume the run time of f(i) is O(1). Below is a code fragment whose asymptotic runtime is Θ(n). It always calls the function f(...) n times. Both the lower and the upper bound is n.

    for(int i=0; i

    The second code fragment below has the asymptotic runtime of O(n). It calls the function f(...) at most n times. The upper bound is n, but the lower bound could be Ω(1) or Ω(log(n)), depending on what happens inside f2(i).

    for(int i=0; i

提交回复
热议问题