Introudction To Algorithms
Introudction To Algorithms
• g(n) essentially provides an upper bound on f(n) i.e. value of f(n) will always be
less than g(n)
• For lower values of n, this might not be true but for sufficiently large n, the value
is always lower than g(n)
• Establishes lowest upper bound
c*g(n)
f(n)
n0
Examples: Big-O
➢3n+3 = O(n) {c = 4: 4n n0 >= 3}
➢10𝑛2 + 4𝑛 + 2 = O(𝑛2 ) {≤ 11𝑛2 ∀𝑛 ≥ 5}
➢6 ∗ 2𝑛 + 𝑛2 = O(2𝑛 ) {≤ 7 ∗ 2𝑛 ∀ 𝑛 ≥ 4}
➢Here, n is the problem size
➢It indicates the number of inputs to the algorithm
➢O(1) or O(p) where p is a constant, indicates that the algorithm takes
constant amount of time no matter what the problem size is
➢That is, the algorithm is independent of the problem size
• The statement f(n) <= g(n) only says that g(n) is an upper bound on
f(n) for all values of n>= n0, but it is silent about how good this upper
bound is.
• But, for the statement f(n) <= g(n) to be informative, the function g(n)
should be as small a function of n as one can come up with
(Big)- Ω Notation
• For a given function f(n) we define Ω(g(n)) to be the set of functions such that
• g(n) essentially provides an lower bound on f(n) i.e. value of f(n) will always be
greater than g(n)
• For lower values of n, this might not be true but for sufficiently large n, the value
is always greater than f(n)
• This establishes highest lower bound
Examples – Big Ω
➢3n+3 = Ω(n) as 3n+3 >= 3n ∀𝑛
➢10𝑛2 + 4𝑛 + 2 = Ω(𝑛2 ) 𝑎𝑠 10𝑛2 + 4𝑛 + 2 ≥ 10𝑛2 ∀𝑛
➢6 ∗ 2𝑛 + 𝑛2 = Ω(2𝑛 ) as 6 ∗ 2𝑛 + 𝑛2 ≥ 6 ∗ 2𝑛 ∀𝑛
➢bound is always chosen as close as possible
➢The function f(n) is only a lower bound on g(n) but for the statement
f(n) = Ω(𝑔 𝑛 ) to be informative g(n) should be as large a function of
n as possible
𝜃 − 𝑁𝑜𝑡𝑎𝑡𝑖𝑜𝑛
f(n) = 𝜃 𝑔(𝑛) 𝑖𝑓𝑓
∃ 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑐1, 𝑐2 𝑎𝑛𝑑 𝑛0 𝑠𝑢𝑐ℎ 𝑡ℎ𝑎𝑡
c1 ∗ g n ≤ 𝑓 𝑛 ≤ 𝑐2 ∗ 𝑔 𝑛 ∀ 𝑛 ≥ 𝑛0
f(n)
c2*g(n)
n0
o-Notation
f(n) = o(g(n)) iff 0<= f(n) < c*g(n) ∀ 𝑛 ≥ 𝑛0
or
𝑓(𝑛)
lim =0
𝑛→∞ 𝑔(𝑛)
or
𝑔(𝑛)
lim =0
𝑛→∞ 𝑓(𝑛)