Big-O (cont)

Download Report

Transcript Big-O (cont)

Big-O (cont)
Outline
•
•
•
•
Definition, discussion of different cases
Properties
Find big-O
examples
Properties of Big-O Notation
• Fact 1 (Transitivity)
– If f(n)=O(g(n)) and g(n)=O(h(n)), then f(n)=O(h(n))
– Prove by definition, need to choose c and N
• Fact 2
– If f(n)=O(h(n)) and g(n)=O(h(n)), then f(n)+g(n)=O(h(n))
– Prove it (done in class)
• Fact 3
– The function ank=O(nk)
– Prove it (done in class)
• Fact 4
– The function nk=O(nk+j) for any positive j
Properties of Big-O Notation (cont’d)
• It follows from those facts that every
polynomial is big-O of n raised to the largest
power
f(n) = aknk + ak-1nk-1 + . . . + a1n1 + a0 = O(nk)
Properties of Big-O Notation (cont’d)
• Fact 5
– If f(n)=cg(n), then f(n)=O(g(n))
• Fact 6
– The function logan = O(logbn) for any positive
numbers a and b  1
– WHY?
• Fact 7
– logan = O(lgn) for any positive a  1, where lg n =
log2n
Examples
• Algorithm, Sum the element in an array, input
n, the size of the array
• For(i = sum=0; I < n; i++)
– sum += a[i];
• O(?)
• P60