1 / 12

MSIS 6 55 Advanced Business Applications Programming

Week 11 Recursion (Ch. 15). MSIS 6 55 Advanced Business Applications Programming. 11 . 1. Introduction. Earlier programs are structured as methods that call one another in a disciplined, hierarchical manner Recursive methods Call themselves

edithg
Download Presentation

MSIS 6 55 Advanced Business Applications Programming

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. Week 11 Recursion(Ch. 15) MSIS 655Advanced Business Applications Programming 11.1

  2. Introduction • Earlier programs are structured as methods that call one another in a disciplined, hierarchical manner • Recursive methods • Call themselves • Useful for some problems to define a method to call itself • Can be called directly or indirectly through another method

  3. Fig. 15.2 | Recursive evaluation of 5!.

  4. Recursion Concepts • If method is called with more complex problem, problem divided into two pieces—a piece the method knows how to do (base case) and a piece the method does not know how to do (called recursive call or recursion step)

  5. Recursion Concepts • Recursive problem-solving elements • Base case • Recursive method capable of solving only simplest case—the base case • If method is called with base case, method returns result • Recursive call/recursion step • Must resemble original problem but be slightly simpler or smaller version • Method calls fresh copy of itself to work on smaller problem • Normally includes return statement

  6. Example Using Recursion: Fibonacci Series

  7. Fig. 15.7 | Set of recursive calls for fibonacci( 3 ).

  8. Recursion and the Method Call Stack • Method call stack used to keep track of method calls and local variables within a method call • Just as with nonrecursive programming, recursive method calls are placed at the top of the method call stack (push) • As recursive method calls return, their activation records are popped off the stack and the previous recursive calls continue executing • Current method executing is always method whose activation record is at top of stack

  9. Fig. 15.8 | Method calls made within the call fibonacci( 3 ).

  10. Fig. 15.9 | Method calls on the program execution stack.

  11. Lab activities (Week 11) • Exercises (pp. 782-783)15.16, 15.17, 15.18 • Advanced: 15.14 (see example on Fig. 15.12 – p. 758)

More Related