Uploaded by seife lakew

Big-Oh Notation Ass

advertisement
Big-Oh Notation
• Definition 1: Let f(n) and g(n) be two functions. We write:
• f(n) = O(g(n)) or f = O(g)
• (read "f of n is in big oh of g of n" or "f is in big oh of g") if there exist
two positive integer C and n0 such that f(n) <= C * g(n) for all positive
integers n > n0.
Big-Oh…
It indicates the upper or highest growth rate that
• the algorithm can have.
The statement “f(n) is in O(g(n))” means that the growth rate of f(n) is
no more than the growth rate of g(n).
We can use the big-Oh notation to rank functions according to their
growth rate.
Big O Example 1
• Let T(n) = 5n + 3, prove that T(n)=O(n).
• To show that T(n) = O(n), we have to show the existence of a constant
c for some sufficiently large n as given in Definition 1 such that 5n + 3
<= cn
• 5n + 3 <= 5n + 3n
• 5n + 3 <=8n
• Therefore, if c = 8, we have shown that T(n) = O(n) for all n>=1.
Big O Example 2
• Let T(n) = 12n7 - 6n5 + 10n2 – 5 prove that T(n)=O(n7).
• To show that T(n) = O(n), we have to show the existence of a constant
c for some sufficiently large n as given in Definition 1 such that 12n7 6n5 + 10n2 – 5 <= cn
•
T(n) =12 n7 - 6n5 + 10n2 - 5
•
T(n) <= 12n7 + 6n7 + 10n7 + 5n7
•
T(n) <= 33n7
• Therefore, if c = 33, we have shown that T(n) = O(n) for all n>=1.
Download