Lower Bounds

Document Sample
Lower Bounds Powered By Docstoc
					Analysis of Algorithim

     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 we’ve
seen for comparison sorting is O(nlgn).

  Is O(nlgn) the best we can do?

Decision trees can help us answer this
               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
• 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
                    y             n
   y          n                                 y          n
        B<C                                         B<C

              y         n             y         n
                  A<C                     A<C
A<B<C                                                     CBA

          A<CB     CA<B BA<C             BC<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
• The height of this particular tree is three
• Can we make a shorter tree which still solves
  the problem?
  – no we can’t. 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