Object-Oriented Design and Data Structures
Recursion is the definition of something in terms of itself. This sounds circular, but with care, recursive definitions can be a highly effective way to express both algorithms and data structures. Recursion allows us to solve a problem by using solutions to “smaller” versions of the same problem. The nth Fibonacci number is the sum of the previous two Fibonacci numbers. This is a recursive definition of a function f(n): To make this definition make sense, we need a base case that stops the recursion definition from expanding indefinitely: Since the recursive definition is always in terms of smaller values of 𝑛 , any given 𝑓 ( 𝑛 ) where 𝑛 ≥ 0 expands into smaller and smaller arguments until the base case is reached. For example: This recursive definition not only makes sense mathematically, it can be implemented in a direct way as Java code: This is very concise code, but not very efficient, as we'll see. An efficient algorithm for exponentiation known as “squaring and multipl
Recursion Recursion is the definition of something in terms of itself. This sounds circular, but with care, recursive definitions can be a highly effective way to express both algorithms and data structures. Recursion allows us to solve a problem by using solutions to “smaller” versions of the same problem. Examples Let's start by looking at some simple examples of using recursion to solve problems. Recursively computing Fibonacci numbers The nth Fibonacci number is the sum of the previous two Fibonacci numbers. This is a recursive definition of a function f(n): To make this definition…
related reading
- How Not to Teach Recursionparentheticallyspeaking.org
- CSC 151 - Recursion over Numberseikmeier.sites.grinnell.edu
- Reading 14: Recursionweb.mit.edu
- Reading 11: Recursive Data Typesweb.mit.edu
- Foundations Of Data Structures And Algorithms | Pier Paolo Ippolitopierpaolo28.github.io
- Structure and Interpretation of Computer Programsmitp-content-server.mit.edu
- Reading 17: Recursive Data Typesweb.mit.edu
- Reading 17: Recursive Data Typesweb.mit.edu
- CSC 151 - Recursion Over Listseikmeier.sites.grinnell.edu
- CSC 151 - Tail Recursioneikmeier.sites.grinnell.edu
- Structure and Interpretation of Computer Programs, 2e: 1.2sarabander.github.io
- how I think when I think about programming - alice mazalicemaz.com