# CMPSCI 251: Mathematics of Computation

### Proofs with Big-O Notation

In lecture this week we gave formal definitions of the big-O and big-Omega notation. Here f and g are functions from N to the reals, ε is a positive real, and n and n0 are naturals.

• f = O(g) &Harr; ∃c:∃n0∀n:(n≥n0) → f(n) ≤ cg(n)
• f = Ω(g) &Harr; ∃ε:∃n0:∀n: (n ≥ n0) → f(n) ≥ εg(n)
• f = Θ(g) &Harr; f = O(g) ∧ f = Ω(g)

Questions are in black, answers in blue.

In this discussion we will use these definitions, and the proof rules for quantified statements from CMPSCI 250, to prove some of the properties of big-O and big-Omega. (Anyone who took 250 from me should remember the rules of Existence, Instantiation, Specification, and Generalization -- I'll go over these on the board as needed.)

• Question 1: Prove that if 0 < α < β, then nα = O(nβ) but nβ ≠ O(nα).

To show the first statement, we can let c=1 and n0 = 1, then because α < β implies nα ≤ nβ for positive n, we are done. If the second statement were true for any c and any n0, for all large n we would have nβ ≤ cnα. But this can't be true for all n, because for large enough n, nβ-α will be bigger than any fixed c.

• Question 2: Prove that if f = Θ(1), then f2 = Θ(f). You probably want two separate proof, one for f2 = O(f) and one for f2 = Ω(f).

To show f2 = O(f), pick c and n0 from the fact that f = O(1) so that n ≥ n0 implies f(n) ≤ c. Then for the same c and n0, n ≥ n0 implies that f2(n) ≤ cf(n).

To show f2 = Ω(f), pick ε and n0 from the fact that f = Ω(1) so that n ≥ n0 implies f(n) ≥ ε. Then for the same ε and n0, n ≥ n0 implies f2(n) ≥ εf(n).

• Question 3: Prove that log(n!) = Θ(n log n). Like Question 2, this naturally breaks into two parts. It is useful to express log(n!) as a sum.

The sum in question is that log(n!) is the sum for i from 1 to n of log(i). To see that log(n!) = O(n log n), note that this sum is ≤ n log n because each term is ≤ log(n). To see that log(n!) = Ω(n log n), note that the sum is ≥ (1/4)(n log n) because the second half of the terms are each bigger than (1/2)(log n) (as long as n is at least 4).

• Question 4: Put the following functions in order by growth rate, so that if f is before g, then f = O(g). Indicate which functions are also related by big-Omega and thus by big-Theta:
• n2log n, 6n log5 n, n2.01, n1/2+17, 27n+35, (n1/2+17)2, (n+17)1/2, 3 + sin n.

• smallest is 3 + sin n, which is Θ(1)
• next are n1/2+17 and (n+17)1/2, which are both Θ(n1/2)
• next are 27n+35 and (n1/2+17)2, which are both Θ(n)
• next is 6n log5n
• next is n2log n
• largest is n2.01