Functional Problem Solving (CSC 151 2015F) : Outlines
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Held: Wednesday, 14 October 2015
Back to Outline 27 - Characters and Strings. On to Outline 29 - Recursion with Helper Procedures, Continued.
Summary
We consider a different form of recursion, one based on the construction of recursive helpers that take additional parameters. Along the way, we consider the idea of tail recursion. We also explore how careless design of recursive procedures can inadvertently lead to slow execution.
Related Pages
Overview
Administrivia
Some programmers find tail recursion much easier to understand. It's certainly easier to chart. And that may make it easier to design. We can also keep track of what's going on a bit better.
Let's do an example: Let's count the number of bright colors in a list.
What should we keep track of along the way?
When are we done?
What do we return?
What do we do in other situations?
Note: For whatever reason, I see some students who find tail recursion very natural and standard recursion confusing, and some students who find standard recursion confusing and tail recursion natural. I'll push you to work on both.
These are from a previous time I taught the class. I leave them around for historical reasons.
'(2 3 5 7 11 13), we end up with (+ 2 (+ 3 (+ 5 (+ 7 (+ 11 (+ 13 (sum ()))))))) (cons "black" (cons "darkblue" (cons "darkgrey" (select-dark ())))) partial-sum unexplored-elements 0 (2 3 5 7 11 13) 2 (3 5 7 11 13) 5 (5 7 11 13) 8 (7 11 13) 15 (11 13) 26 (13) 39 ()