Recurrence Relations - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Recurrence Relations

Description:

... 218 in the book. Master Theorem. Administrative. Irena's office hours: Friday 2:30-4:30 ... Irena's office hours: Friday 2:30-4:30. Questions from the homework: ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 9
Provided by: scie350
Category:

less

Transcript and Presenter's Notes

Title: Recurrence Relations


1
Lecture 4
  • Recurrence Relations

2
Examples
  • Binary Search recurrence relation p. 21 in the
    book
  • Towers of Hanoi recurrence relation ch. 2, p.
    18-21 in the book
  • Merge Sort recurrence relation ch. 9.3, p.
    215-218 in the book
  • Master Theorem

3
Administrative
  • Irenas office hours Friday 230-430
  • If time allows, at the end of class Ill take
    questions from the homework
  • Do some limits using lHospital Rule, taking the
    derivative of a product, ln x
  • More proofs by induction (ex. 2 ch 1 book)

4
Analysis of Recursive AlgorithmsRecurrence
Relations
  • Binary Search worst case analysis
  • T(n) T(n/2)1, T(1)1
  • Assume n2k (i.e. k log2n)
  • T(2k)T(2 k-1)1T(2k-2) 2
  • T(2k-i)i T(20)kk1
  • log 2n 1 O(log n)
  • T(n) O(log n)

5
Towers of Hanoi
  • Show algorithm. End of the World legend.
  • T(n)2T(n-1)1 and T(0)0
  • T(n)2T(n-1)12(2T(n-2)1)1
  • 22 T(n-2)(2 1)
  • 22 (2 T(n-3) 1) 2 1 23 T(n-3) (22 2
    1)
  • . 2i T(n-i) (2i-1 2 1)
  • 2n T(n-n) (2n-1 2 1)
  • 2n T(0) 2n - 1 2n - 1 O(2n)

6
Merge Sort
  • Input array A of n numbers
  • Output array in sorted order
  • Algorithm
  • divide the array in 2 (left and right)
  • recursively sort left and right arrays
  • merge the tow sorted arrays into a single one

7
Analysis of Merge Sort
  • T(n) 2T(n/2) n
  • 2(2T(n/22) n/2) n
  • 22 T(n/22) n n 2 2 T(n/ 22) 2n
  • 22 (2 T((n/22)/2) n/22) 2n
  • 23 T(n/23) 3n
  • 2k T(n/2k) kn.
  • For n 2k (k log2 n) and T(1) 0 we get
  • T(n)n log2 n O(n log n)

8
Administrative
  • Irenas office hours Friday 230-430
  • Questions from the homework
  • Do some limits using lHospital Rule, taking the
    derivative of a product, ln x
  • More proofs by induction (ex. 2 ch 1 book)
Write a Comment
User Comments (0)
About PowerShow.com