Introduction to Algorithms : Recurrence
Print this page
 
 


   Another way of finding number of instruction executed is by recursive equation. Let T(n) be the time required to   sort n numbers. T(n) can be expressed as a sum of T(n-1) and the time required to insert nth element in the   sorted array of n-1 element.

    The time required to insert an element in sorted array of n-1 elements takes cn steps, where c is a positive       constant. This is because to insert nth element, in worst case, we have to shift all n-1 elements one after other.    

   See the following figure.

       
Prev