









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of recursion, a fundamental concept in computer science. Recursion is a method where a function calls itself, and this document covers its basics, examples, and applications. Topics include recursive calls, ending cases, recursive delete, fibonacci sequence, root finding, and dictionary search.
Typology: Slides
1 / 16
This page cannot be seen from the preview
Don't miss anything!










Change in schedule!
No fancy blue words or classes this chapter Recursion is simply calling a method from inside itself This copy will re-run the method on any new arguments or information (See: BadRecursion.java)
Good recursion must have 2 parts:
A child couldn't sleep, so her mother told a story about a little frog, who couldn't sleep, so the frog's mother told a story about a little bear, who couldn't sleep, so bear's mother told a story about a little weasel ...who fell asleep. ...and the little bear fell asleep; ...and the little frog fell asleep; ...and the child fell asleep. Docsity.com
Remember, code starts in main and runs from top to bottom in sequence (normally) When you call a method you go execute all the method code is run before going back to the original code This means code order is important in recursion (See: StringRecursion.java)
The Fibonacci numbers are defined as: F(n) = F(n-1) + f(n-2) In other words, you add the previous two to get the next This is recursion! Computing F(n) involves solving smaller problems of F(n-1) (See: FibonacciRecursion.java) Docsity.com
Find a root of:
"To understand recursion, you must understand recursion." Try googling “recursion” and click on the spelling suggestion We will probably see more of this when we talk about linked lists (Some data types are conducive to recursion)Docsity.com