Programming in c++ Recursion Dale/eems/Headington
1 Recursion
Programming in C++ Chapter 15 Topics Meaning of Recursion Base Case and General Case in Recursive Function definitions s Writing Recursive Functions with Simple Type Parameters s Writing Recursive Functions with Array Parameters wRiting Recursive Functions with Pointer Parameters Understanding How Recursion Works
2 Chapter 15 Topics ❖Meaning of Recursion ❖Base Case and General Case in Recursive Function Definitions ❖Writing Recursive Functions with Simple Type Parameters ❖Writing Recursive Functions with Array Parameters ❖Writing Recursive Functions with Pointer Parameters ❖Understanding How Recursion Works
Programming in C++ Recursive Function Call s a recursive call is a function call in which the called function is the same as the one making the call in other words, recursion occurs when a function calls itself g but we need to avoid making an infinite sequence of function calls (infinite recursion)
3 Recursive Function Call ❖a recursive call is a function call in which the called function is the same as the one making the call ❖in other words, recursion occurs when a function calls itself! ❖but we need to avoid making an infinite sequence of function calls (infinite recursion)
Programming in C++ Finding a Recursive Solution oa recursive solution to a problem must be written carefully & the idea is for each successive recursive call to bring you one step closer to a situation in which the problem can easily be solved o this easily solved situation is called the base case g each recursive algorithm must have at least one base case, as well as a general case (recursive case)
4 Finding a Recursive Solution ❖a recursive solution to a problem must be written carefully ❖the idea is for each successive recursive call to bring you one step closer to a situation in which the problem can easily be solved ❖this easily solved situation is called the base case ❖each recursive algorithm must have at least one base case, as well as a general case (recursive case)
Programming in C++ General format for Many Recursive Functions if (some easily-solved condition) //base case solution statement else ∥ genera/case recursive function call SOME EXAMPLES
5 General format for Many Recursive Functions if (some easily-solved condition) // base case solution statement else // general case recursive function call SOME EXAMPLES . .