Proving and Disproving BigO

后端 未结 1 1748
陌清茗
陌清茗 2021-02-09 01:57

In proving and disproving Big O questions that explicitly say use the definition to prove and disprove, my question is, is what I am doing correct?

For example you have

1条回答
  •  清酒与你
    2021-02-09 02:26

    Neither of your techniques work. Let's start with the definition of big-O:

    f is O(g) iff there exist C, N such that |f(x)| ≤ C |g(x)| for all x ≥ N

    To prove "there exist" type statements, you need to show that, well, the things exist. In the case of big-O proofs, you usually find the things, though proofs of existence don't generally need to be constructive. To build a proof for a "for all" statement, pretend someone just handed you specific values. Be careful you make no implicit assumptions about their properties (you can explicitly state properties, such as N > 0).

    In the case of proving big-O, you need to find the C and N. Showing |g(n)| ≤ C|F(n)| for a single n isn't sufficent.

    For the example "n2+3 is O(n2)":

     For n ≥ 2, we have: 
        n2 ≥ 4 > 3
          ⇒ n2-1 > 2
          ⇒ 2(n2-1) > (n2-1)+2
          ⇒ 2n2 > (n2-1)+4 = n2+3
     Thus n2+3 is O(n2) for C=2, N=2.
    

    To disprove, you take the negation of the statement: show there is no C or N. In other words, show that for all C and N, there exists an n > N such that |f(n)| > C |g(n)|. In this case, the C and N are qualified "for all", so pretend they've been given to you. Since n is qualified "there exists", you have to find it. This is where you start with the equation you wish to prove and work backwards until you find a suitable n.

    Suppose we want to prove that n is not O(ln n). Pretend we're given N and C, and we need to find an n ≥ N such that n > C ln n.

    For all whole numbers C, N, let M=1+max(N, C) and n = eM. Note n > N > 0 and M > 0.
    Thus n = eM > M2 = M ln eM = M ln n > C ln n. QED.
    

    Proofs of x > 0 ⇒ ex > x2 and "n is not O(ln n)" ⇒ "n is not O(logb n)" left as exercises.

    0 讨论(0)
提交回复
热议问题