1 / 14

03/07/13

Recursive Definition. 03/07/13. Discrete Structures (CS 173) Derek Hoiem, University of Illinois. Last class: induction. False induction proofs All professors have the same color shoes. Other good examples: http://www.math.uiuc.edu/~hildebr/347/induction3-sol.pdf. overhead.

dillian
Télécharger la présentation

03/07/13

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recursive Definition 03/07/13 Discrete Structures (CS 173) Derek Hoiem, University of Illinois

  2. Last class: induction • False induction proofs • All professors have the same color shoes. • Other good examples: http://www.math.uiuc.edu/~hildebr/347/induction3-sol.pdf overhead

  3. Today’s lecture: Recursive Definitions • Be able to write a series as a recursive function • Be able to “unroll” a recursive function and find the closed form • Prove closed form of recursive function using induction • Examples, including divide and conquer algorithm

  4. Defining recursive functions A recursive function has two parts: base case: recursive formula: , for n Example:  base case  recursive formula

  5. Examples

  6. Examples 1 1,1 Pascal’s Triangle 1 1 2,2 2,1 1 2 1 3,1 3,2 3,3 1 3 3 1

  7. Examples The series: 1, 2, 2, 4, 8, 32, 64, … (each number is the product of previous two)

  8. Finding closed form

  9. Process for finding closed form • “Unroll” for several steps until the pattern becomes clear • Solve for • Find for base case • Substitute value for base case • Simplify • Check answer

  10. Example: how many edges in a N-d hypercube?

  11. Proof of closed form solution by induction Claim: For all natural ,

  12. Example: divide and conquer computation • A divide and conquer algorithm recursively splits a problem of size into two smaller problems, each of size . • Suppose it costs time to make the split and when the function returns a value in constant time . • Problem: Write cost as a recursive function , solve for closed form, and prove that solution is correct.

  13. Things to remember • Be able to write a series as a recursive function • Process for finding closed form • Unroll for several steps • Write in terms of • Substitute for value of that is base case • Substitute base case value(s) and solve • Closed form solutions can be proved with induction

  14. Next week • Trees

More Related