I am learning about analysis of algorithms. I understand the concept of the worst case running time of an algorithm.
However, what are upper and lower bounds on the worst case running time of an algorithm?
What can be an example where an upper bound for the worst case running time of an algorithm is different from the lower bound for the worst case running time of the same algorithm?
Yes, it can mean worst case synonymous with upper bound and best case synonymous with lower bound. Worst-case performance is the most used in algorithm analysis. In the worst-case analysis, we guarantee an upper bound on the running time of an algorithm which is good information.
Proving an upper bound means you have proven that the algorithm will use no more than some limit on a resource. Proving a lower bound means you have proven that the algorithm will use no less than some limit on a resource. "Resource" in this context could be time, memory, bandwidth, or something else.
The upper bound is not the same as the worst case. We don't want to tie best and worst cases to input size.
It gives an upper bound on the resources required by the algorithm. In the case of running time, the worst-case time complexity indicates the longest running time performed by an algorithm given any input of size n, and thus guarantees that the algorithm will finish in the indicated period of time.
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]
If g(n)
is both upper bound and lower bound of f(n)
[with different c's], we say g(n) is a tight bound for f(n) [Big theta]
Use example for upper bound instead of tight one: Sometimes, it is hard to find tight bound, such as the fibonacci recursive algorithm. So we find an easy upper bound of O(2^n) easily. more info is found in answers in this post.
How does it related to worst/base/... cases? (as requested by comments):
Worst case/average case (or any other case) affects what the complexity function is, but big-O, big-Omega, and big-Theta can be applied to each of these cases.
For example, a HashTable insert is Θ(1)
average case insertion, and Θ(n)
worst case insertion. It is also O(n)
average case insertion (bound is not tight), and Ω(1)
worst case insertion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With