03-Recursion(1) (1).ppt - King Fahd University of Petroleum Minerals College of Computer Science Engineering Information Computer Science Department

# 03-Recursion(1) (1).ppt - King Fahd University of Petroleum...

This preview shows page 1 - 9 out of 39 pages.

Unit 3 Recursion King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department
Reading Assignment “Data Structures and Algorithms in Java”, 3 rd Edition, Adam Drozdek, Cengage Learning, ISBN 978-9814239233 Chapter 5 Sections 1-8, 10. Backtracking and the Case Study in Sections 9 and 11 are optional reading.
Objectives Discuss the following topics: Recursive Definitions Method Calls and Recursion Implementation Tracing of Recursive Methods Tail and Non-Tail Recursive Methods Direct and Indirect Recursive Methods Nested and non-Nested Recursive Methods Excessive Recursion Final Remarks on Recursion 3
Recursive Definitions Recursive definitions are programming concepts that define themselves A recursive definition consists of two parts: The anchor or ground case , the basic elements that are the building blocks of all other elements of the set Rules that allow for the construction of new objects out of basic elements or objects that have already been constructed 4
Recursive Definitions (continued) Recursive definitions serve two purposes: Generating new elements Testing whether an element belongs to a set Recursive definitions are frequently used to define functions and sequences of numbers 5
What is a Recursive Method?
What is a Recursive Method?7
Method Calls and Recursion Implementation When a method is called an Activation Record is created. It contains: The values of the parameters. The values of the local variables. The return address (The address of the statement after the call statement). The previous activation record address. A location for the return value of the activation record. When a method returns: The return value of its activation record is passed to the previous activation record or it is passed to the calling statement if there is no previous activation record.

#### You've reached the end of your free preview.

Want to read all 39 pages?

• Winter '12
• Ghouti