1 / 7

Recursion

Recursion. Dilshad M. Shahid New York University @1999. Today. Definition Features of Recursion Recursion Examples Recursion vs Iteration. Definition. A recursive function is a function that calls itself either directly or indirectly through another function

Download Presentation

Recursion

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. Recursion Dilshad M. Shahid New York University @1999

  2. Today • Definition • Features of Recursion • Recursion Examples • Recursion vs Iteration

  3. Definition • A recursive function is a function that calls itself either directly or indirectly through another function • A recursive function is called to solve a problem • the function knows only how to solve the simplest case (base case)

  4. Definition • if function is called with a base case, it simply returns the result • if function is called with a more complex problem, it divides the problem into 2 conceptual pieces - a piece it knows how to do and a piece it doesn’t

  5. Features of Recursion • Remember, a recursive function is one that calls itself • The object of a recursive function is to reduce a complex problem to a simple case (base case) that it can solve, and then work forward step by step, solving each step until the solution to the original problem is found • So in order for the recursion to eventually terminate, the sequence of smaller and smaller problems must eventually converge on the base case

  6. Recursion Examples • Factorial example • Fibonacci sequence example • Both on webpage

  7. Recursion vs Iteration • See section 5.15 on page 180 of your text

More Related