Lower Bounds
Adversarial Arguments
Example 1
We can find the maximum element in an unsorted array in time. How can we argue that this is optimal?
Idea: Show that any algorithm which executes a number of steps that is "too small" can be fooled by at least one input.
We show that with only steps, we cannot find the max in the array.
Adversary strategy:
- When the algorithm asks for the number at position in , we return 0.
- We tell the algo: now that you executed your steps, go ahead if you're so smart: tell us what is the max?
So we cannot solve this in at most steps, we need steps. Therefore is optimal.
Example 2
We can find the median in an array in O(n) time using the selection algorithm. Can we do better?
We will prove that with at most steps no algo can compute the median.
Adversary strategy:
- When the algo asks for the number at position in , we return .
- Algo says is median, but we say that missing value is such a value that is different
So it takes $\Omega ((n-1) + 1) steps to compute the median.
Decision Trees
The Sorting Problem
A decision tree is a binary tree defined as follows:
- has a finite number of nodes
- the label of each internal node of is of the form
- from each internal node of , there are two outgoing edges:
- the label of the left outgoing edge is
- the label of the right outgoing edge is
To each decision tree corresponds an algorithm . Conversely, to each algorithm which uses only comparisons () corresponds a decision tree .
Theorem
In the decision tree model, sorting an array of numbers takes time.
Find an Element in a Sorted Array
In the decision tree mode, finding the position of an element in a sorted array (or detecting that is not in ) takes time.
Merging Two Sorted Arrays
Let and be two sorted arrays. We know how to merge and into one single sorted array in time.