Search code examples
algorithmtime-complexitylower-boundupperbound

Upper bounds and Lower bounds in Algorithms


I saw several articles describing upper bound as Best Case and Lower bound as Worst Case. Meanwhile some articles have given explanations for Upper /Lower bound of Worst Case.

So basically this got me asking three questions:

  1. What exactly are Upper/Lower bounds?
  2. How can they be defined separately in a Worst Case scenario?
  3. Can bounds be defined for other cases(Best,Average) as well?

Solution

  • What exactly are Upper/Lower bounds?

    We are interested in bounds of functions, as you can read in Wikipedia.

    Moreover, a part of this answer mentions:

    For a function f(n), g(n) is an upper bound (big O) if for "big enough n", f(n)<=c*g(n), for a constant c. [g dominates f]
    g(n) is lower bound (big Omega) if for "big enough n", f(n) >= c*g(n), for a constant c. [f dominates g]

    How can they be defined separately in a Worst Case scenario?

    They are either going to be different, or the same; in that case we say Θ(n), where n is usually the size of the problem. As Dukeling said:

    Worse, best and average cases can* be represented as a function (for terminating algorithms). Each of those functions has upper and lower bounds (of which there are infinitely many). Doing a constant number of operations per element (e.g. the best case for insertion sort and average/worst case for linear search) would have a tight bound (lower and upper bound) of Θ(n), but also an upper bound of O(n2) or a lower bound of Ω(1).

    Can bounds be defined for other cases(Best,Average) as well?

    Yes. It is possible that all the cases have their upper and lower bounds.