Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Running Time Analysis

The running time of the recursive DoSort routine (Program gif) is given by

  equation37850

where n is the number of elements in sequence to be sorted, tex2html_wrap_inline70173 is the running time of the SelectPivot function, and i is the number of elements which end up to the left of the pivot, tex2html_wrap_inline70177.

The running time of DoSort is affected by the SelectPivot routine in two ways: First, the value of the pivot chosen affects the sizes of the subsequences. I.e., the pivot determines the value i in Equation gif. Second, the running time of the SelectPivot routine itself, tex2html_wrap_inline70173, must be taken into account. Fortunately, if tex2html_wrap_inline70183, we can ignore its running time because there is already an O(n) term in the expression.

In order to solve Equation gif, we assume that tex2html_wrap_inline70183 and then drop the tex2html_wrap_inline58163s from the recurrence to get

  equation37861

Clearly the solution depends on the value of i.




next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.