Professional Documents
Culture Documents
Quiz
Explain:
Hierarchy of Orders for Algorithm
Maximum Rule of the Orders of Algorithm
Analysis of Algorithm
Lower Bounds
Lower Bounds
All the sorting algorithms we have seen so far
are comparison sorts: only use comparisons to
determine the relative order of elements.
The best worst-case running time that weve
seen for comparison sorting is O(nlgn)
Is O(nlgn) the best we can do?
Decision trees can help us answer this
question.
Lower bounds
The basic idea is to expand the problem into a
complete decision tree
The leaves of the tree are where the algorithm
terminates (i.e. our problem has been decided)
there are therefore as many leaves as possible
outcomes
B<C
A<B
n
y
n
y
A<C
A<C
B<C
A<B<C
CBA
A<CB
CA<B BA<C
BC<A
A Shorter Tree?
Any sorting by comparison algorithm must be a
decision tree of some kind, although it might be
much bigger if the algorithm is inefficient
e.g. the same comparison could appear in many
places
Decision-tree model
A decision tree can model the execution of any
comparison sort:
One tree for each input size n.
View the algorithm as splitting whenever it
compares two elements.
The tree contains the comparisons along all
possible instruction traces.
The running time of the algorithm =the length of
the path taken.
Worst-case running time =height of tree.