You are on page 1of 9

Quiz

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

The height and branching factor of the tree give


us an indication of the complexity of the problem
for simplicity we restrict ourselves to binary trees operations such as comparison are binary in any case

Decision Tree for Sorting 3 Items


y
y

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

The height of this particular tree is three


comparisons
Can we make a shorter tree which still solves the
problem?
no we cant. A binary tree with only two levels has at
most four leaves, but there are six possible
permutations of three items

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.

Lower bound for decision-tree sorting

You might also like