CSC 151 - Recursion over Numbers
Our recursive functions mirror this recursive definition. So it stands to reason that if we are able to give a recursive definition for any type, then we can perform recursion over that type similarly! Many kinds of data admit recursive definitions, and you will encounter many of them throughout your computer science journey. However, there is one datatype that trumps them all—perhaps even more so than a list! It is the natural number. Recall that the natural numbers are the non-negative integers. This includes the numbers 0 0 , 1 1 , 2 2 , 3 3 , …, etc. Our definition of a list was recursive because at least one of the cases included a smaller list inside itself. We can see via the picture where the smaller list is located: it’s the tail of the list! However, now let’s consider a natural number, say 5 5 : Ugh. Unlike lists, it is not immediately obvious what the “smaller” natural number is in this situation. Where is it hiding? One way to discover where the smaller natural number
CSC 151 - Recursion over Numbers Recursion over Numbers Due Friday, 17 October 2025 --> The heart of our recursive functions so far is our recursive definition of lists: A list is either: Empty ( null ) or Non-empty ( ( cons head tail ) ) with a head element and a sub-list, its tail . Our recursive functions mirror this recursive definition. So it stands to reason that if we are able to give a recursive definition for any type, then we can perform recursion over that type similarly! Many kinds of data admit recursive definitions, and you will encounter many of them throughout your computer sci
Explore this link on the map →saved by
related reading
- CSC 151 - Recursion Over Listseikmeier.sites.grinnell.edu
- CSC 151 - Pattern matchingeikmeier.sites.grinnell.edu
- CSC 151 - Higher-order design, recursive and othereikmeier.sites.grinnell.edu
- CSC 151 - Tail Recursioneikmeier.sites.grinnell.edu
- CSC 151 - Coding Challenge 7eikmeier.sites.grinnell.edu
- CSC 151 - Coding Challenge 6eikmeier.sites.grinnell.edu
- CSC 151 - Analyzing procedureseikmeier.sites.grinnell.edu
- CSC 151 - Decompositioneikmeier.sites.grinnell.edu
- How Not to Teach Recursionparentheticallyspeaking.org
- Reading 11: Recursive Data Typesweb.mit.edu
- Structure and Interpretation of Computer Programsmitp-content-server.mit.edu
- Reading 14: Recursionweb.mit.edu