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

SparkLife

Star Trek gets SEXY

Chris Pine and Zoe Saldana heat up the red carpet!

SparkLife

Are you afraid of relationships?

Auntie SparkNotes can help!

SparkLife

Wanna get JLaw's gorgeous glow?

Click here for simple, sexy makeup tricks!

SparkLife

Sexy starlet style

See every single look from the Met Gala!

SparkLife

Who'd be on your zombie-apocalypse crew?

We already dib'sed Genghis Khan.

Geek out!

The MindHut

Geeky Actresses: Then and Now

Before the fame!

The MindHut

9 Scientific Inaccuracies in Iron Man 3

Click to see what they got wrong.

The MindHut

Top 10 Predictions Sci-Fi Got WRONG

So wrong, they're WRONG.

The MindHut

The 15 Most Awesome Robots, Ever

These Robots Rock!

The MindHut

If You Like Game of Thrones...

...Then you'll LOVE these books!

The Book

Cover image

Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps