50 likes | 162 Views
Recursion: The Real Bear Game. March 27, 2006. Outline. Handouts(1) Perils of JavaSchools Announcements Properties of Successful Recursive Algorithms Three Bears + 1 Box Stuffing. Successful Recursion. Has to Stop Reentrant. Three Bears + 1. X = # of bears
E N D
Recursion: The Real Bear Game March 27, 2006
Outline • Handouts(1) • Perils of JavaSchools • Announcements • Properties of Successful Recursive Algorithms • Three Bears + 1 • Box Stuffing
Successful Recursion • Has to Stop • Reentrant
Three Bears + 1 • X = # of bears • If X is odd, the new number of bears that you have is 3 * X + 1 • If X is even, the new number of bears that you have is X / 2. • For all X, does this sequence always converge to 1 bear?
Box Stuffing • The problem is to exactly (or mostly) fit a box with sets of teddy bears. • If you have bears in sets of 1, 2, 3, 5, 10, 15, and 20, can you fit a box with the capacity of 27?