Solving Recurrence Relations Iteration method Steps Expand the recurrence

Solving recurrence relations iteration method steps

This preview shows page 9 - 15 out of 17 pages.

Solving Recurrence Relations - Iteration method Steps: Expand the recurrence Express the expansion as a summation by plugging the recurrence back into itself until you see a pattern. Evaluate the summation In evaluating the summation one or more of the following summation formulae may be used: Arithmetic series: Geometric Series: Special Cases of Geometric Series: 9
Image of page 9
Solving Recurrence Relations - Iteration method Harmonic Series: Others: 10
Image of page 10
Analysis Of Recursive Factorial method Example 1: Form and solve the recurrence relation describing the number of multiplications carried out by the factorial method and hence determine its big-O complexity: long factorial (int n) { if (n == 0) return 1; else return n * factorial (n – 1); } 11 0 0 ( ) ( 1) 1 0 0 n T n T n n n n
Image of page 11
Analysis Of Recursive Towers of Hanoi Algorithm The recurrence relation describing the number of times is executed for the method hanoi is: public static void hanoi(int n, char from, char to, char temp){ if (n == 1) System.out.println(from + " --------> " + to); else{ hanoi(n - 1, from, temp, to); System.out.println(from + " --------> " + to); hanoi(n - 1, temp, to, from); } } the printing statement 12
Image of page 12
Analysis Of Recursive Towers of Hanoi Algorithm 13
Image of page 13
Analysis Of Recursive Binary Search The recurrence relation describing the number of for the method is: public int binarySearch (int target, int[] array, int low, int high) { if (low > high) return -1; else { int middle = (low + high)/2; if (array[middle] == target) return middle; else if(array[middle] < target) return binarySearch(target, array, middle + 1, high); else return binarySearch(target, array, low, middle - 1); } } element comparisons 14
Image of page 14
Image of page 15

You've reached the end of your free preview.

Want to read all 17 pages?

  • Summer '14
  • Mr.SaidAbdallah
  • Recursion, Recurrence relation

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture