Sierpi ski, Recursion and Efficiency, Mutual Recursion Checkout - - PowerPoint PPT Presentation

sierpi ski recursion and efficiency mutual recursion
SMART_READER_LITE
LIVE PREVIEW

Sierpi ski, Recursion and Efficiency, Mutual Recursion Checkout - - PowerPoint PPT Presentation

Sierpi ski, Recursion and Efficiency, Mutual Recursion Checkout Recursion2 project from SVN } Any method that calls itself On a simpler problem So that it makes progress toward completion Indirect t recursion: May call another


slide-1
SLIDE 1

Sierpiński, Recursion and

Efficiency, Mutual Recursion

Checkout Recursion2 project from SVN

slide-2
SLIDE 2
slide-3
SLIDE 3

} Any method that calls itself

  • On a simpler problem
  • So that it makes progress toward completion
  • Indirect

t recursion: May call another method which calls back to it.

slide-4
SLIDE 4

} When implementing a recursive definition } When implementing methods on recursive

data structures

} Where parts of the whole look like smaller

versions of the whole

Q1

slide-5
SLIDE 5

} The pros

  • easy to implement,
  • easy to understand code,
  • easy to prove code correct

} The cons

  • Sometimes takes more space and time than

equivalent iterative solution

  • Why?

– because of function calls

Q2

slide-6
SLIDE 6

} Always have a bas

base cas e case e that doesn’t t recurse

} Make sure recursive case always makes

prog progres ress, by so solving lving a a smaller smaller pro roblem lem

} Yo

You gotta tta believe

  • Trust in the recursive solution
  • Just consider one step at a time
slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9

HW 11 & 12: Sierpinski Triangle

slide-10
SLIDE 10

} Why does recursive Fibonacci take so long?!? } Can we fix it? Q3

slide-11
SLIDE 11

} Save every solution we find to sub-problems } Before recursively computing a solution:

  • Look it up
  • If found, use it
  • Otherwise do the recursive computation

Q4

slide-12
SLIDE 12

} A deep discovery of computer science } In a wide variety of problems we can tune the

solution by varying the amount of storage space used and the amount of computation performed

} Studied by “Complexity Theorists” } Used everyday by software engineers

slide-13
SLIDE 13

} 2 or more methods call each other repeatedly

  • E.g., Hofstadter Female and Male Sequences

  • In how many positions do the sequences differ

among the first 50 positions? first 500? first 5,000? first 5,000,000?

Q5

http://en.wikipedia.org/wiki/Hofstadter_sequence

slide-14
SLIDE 14
slide-15
SLIDE 15

HW 12: Sierpinski Carpet

Q6-7