This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ≪ x ≪ " to top of tower " ≪ y ≪ endl; TowersOfHanoi(n-1, z, y, x); } } Call TowersOfHanoi( n, 1, 2, 3 ) There is an animation on Tower of Hanoi in the course webpage under the “many applets” link. COMP 152, Spring 2010 Tower of Hanoi 3 Complexity The time taken is proportional to the number of lines of output generated, and the number of lines output is equal to the number of disk moves performed. moves ( n ) = n = 0 2 moves ( n − 1) + 1 n > This yields move ( n ) = 2 n − 1 , i.e., the total number of moves is exponential — which takes very long time if n is large!...
View Full Document