Examples of Recursion


Problems

Problem : Write a function that takes the same arguments as TOH but instead of printing out the solution, returns the number of disc moves in solving the problem.


Problem : If the only change in the rules of the Towers of Hanoi problem were that you only had two poles instead of three, would the problem still be solvable?


Problem : If you have a problem that has a recurrence relation of T(n) = 2T(n/2) + 1, T(1) = 1 , what would be an appropriate big-O notation?


Problem : CHALLENGE: Write an iterative solution to the Towers of Hanoi problem.


Problem : In the iterative solution presented above, what is the purpose of the 1 << n? How does this relate to Towers of Hanoi?


Take a Study Break

Green YOUR SCHOOL!

Click here to get involved with dosomething.org!

John Krasinski's BIG MIRACLE

Click to watch the trailer and read exclusive star interviews!

Do you like Anna?

Read Dear Albert... from ANNA's perspective!

BATTLESHIP, the movie

Here's why we're super jazzed about it.

Do energy juices actually work?

Our blogger puts 'em to the test!


The Book

Cover image

Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps