# Class 16: Recursion

Back to Algorithm Analysis. On to Binary Search.

Held Friday, February 19

Summary

• Exam 1 distributed. Due Friday, February 26.
• Introduction to recursion.
• Due: assignment 4: A Testing Program
• Due: assignment 5 (optional): A Simple Drawing Program

Contents

Handouts

Notes

• Thanks for all the comments on the lab manual. I do note that I've received few requests for explicit acknowledgements. If you want to be acknowledged, let me know ASAP.
• A number of people seemed to expect to find me in the office yesterday. Thursday's are my ``project day'', which means that I'm typically working on something intensive, such as an exam. You should not expect to be able to ask me questions on Thursday. (Next Thursday is an exception, since you have an exam due.)
• Advance warning: I'll be gone next Wednesday afternoon, so you'll need to find me in the morning or on Thursday.
• No, you don't have to do an assignment in addition to the exam. You should, however, keep up on the readings.
• How long did assignment 4 take? Should I be striving for shorter assignments?
• I warned you that I wouldn't be grading every assignment, and I won't be grading this assignment. If you think you did something particularly interesting or worthy of extra credit, send me email and I'll look for it.
• I will, however, try to come up with some notes and something resembling an answer key.
• On Monday at noon, there is a meeting to discuss summer research opportunities in computer science at Grinnell.
• On Tuesday at 12:15 in 2413, there is an informational meeting on an MBA Program with specialization in information and software systems. It seems that students will receive a \$20,000 fellowship plus tuition.

## Recursion

• You've studied Scheme, so you should know about recursion.
• It's not much different in Java.
• A recursive function is a function which calls itself, either directly or indirectly.
• A function calls itself indirectly by calling another function which calls the original function.
• Recursion provides one mechanism for looping.
• Many mathematicians and computer scientists consider recursion significantly more elegant than for or while loops.
• The body of a typical recursive function looks like
```if (some-test) {
base-case;
}
else {
call-it-again-with-modified-parameters;
}
```
• More serious discussion next week.

## Lab

Do A1.3 and A1.4.

History

• Created Monday, January 11, 1999
• Added short summary on Friday, January 22, 1999
• Started to fill in the details on Thursday, February 18, 1999.
• Added a few more notes on Friday, February 19, 1999.
• Made a few small changes on Monday, February 22, 1999.

Back to Algorithm Analysis. On to Binary Search.

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.