Still sort of confused about Big O notation

后端 未结 3 784
感情败类
感情败类 2021-02-09 03:17

So I\'ve been trying to understand Big O notation as well as I can, but there are still some things I\'m confused about. So I keep reading that if something is O(n), it usua

3条回答
  •  半阙折子戏
    2021-02-09 04:11

    Informally speaking, best case has O(n) complexity means that when the input meets certain conditions (i.e. is best for the algorithm performed), then the count of operations performed in that best case, is linear with respect to n (e.g. is 1n or 1.5n or 5n). So if the best case is O(n), usually this means that in the best case it is exactly linear with respect to n (i.e. asymptotically no smaller and no bigger than that) - see (1). Of course, if in the best case that same algorithm can be proven to perform at most c * log N operations (where c is some constant), then this algorithm's best case complexity would be informally denoted as O(log N) and not as O(N) and people would say it is O(log N) in its best case.

    Formally speaking, "the algorithm's best case complexity is O(f(n))" is an informal and wrong way of saying that "the algorithm's complexity is Ω(f(n))" (in the sense of the Knuth definition - see (2)).

    See also:

    (1) Wikipedia "Family of Bachmann-Landau notations"

    (2) Knuth's paper "Big Omicron and Big Omega and Big Theta"

    (3) Big Omega notation - what is f = Ω(g)?

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

    (5) What is a plain English explanation of "Big O" notation?

提交回复
热议问题