JMU
Recursive Thinking
An Introduction to Recursive Algorithms


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Definitions
Nerd Humor

There are two kinds of people in the world, those who divide the world into two kinds of people and those who do not.

Recursion (n) See "Recursion"

GNU

https://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/Droste-wikipedia.jpg/320px-Droste-wikipedia.jpg

http://imgs.xkcd.com/comics/win_by_induction.png
(Courtesy of xkcd)

Nerd Humor (cont.)
http://imgs.xkcd.com/comics/model_rail.png
(Courtesy of xkcd)
What Do These "Jokes" Have In Common?
Using Recursion in Definitions
Using Recursion in Definitions (cont.)
Using Recursion in Definitions (cont.)
From Definition to Algorithm
Designing Recursive Algorithms
An Obvious Example - Factorial
An Example - Print the Digits of a Number
About Printing the Digits of a Number
An Example - Searching through a Book
About Searching through a Book
An Example - Making Change
About Making Change
Thinking Recursively - A Summary
Thinking Recursively - An Observation

Recursive algorithms can be elegant, but require a different way of thinking (which can be difficult):

comics/Hackles-Recursion.png
(Courtesy of Hackles)
Algorithms Involving Recursion