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(n1, 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
This note was uploaded on 08/25/2010 for the course COMP COMP152 taught by Professor D.y.yeung during the Spring '10 term at HKUST.
 Spring '10
 D.Y.Yeung
 ObjectOriented Programming, Data Structures

Click to edit the document details