Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tower of hanoi

909 views

Published on

Tower of Hanoi Problem solved through recursive algorithm

Published in: Education
  • Be the first to comment

Tower of hanoi

  1. 1. Tower of Hanoi
  2. 2. What???? • Three pegs, one with n disks of decreasing diameter; two other pegs are empty
  3. 3. Objective The Objective is to transfer the entire tower to one of the other pegs.
  4. 4. Rules • Only one disk may be moved at a time. Specifically, only the top disk on any disk on any peg may be moved to any other peg. • At no time can a larger disk be placed on a smaller disk.
  5. 5. Tower of Hanoi
  6. 6. Tower of Hanoi
  7. 7. Tower of Hanoi
  8. 8. Tower of Hanoi
  9. 9. Tower of Hanoi
  10. 10. Tower of Hanoi
  11. 11. Tower of Hanoi
  12. 12. Tower of Hanoi
  13. 13. Tower of Hanoi
  14. 14. Algorithm Let’s call the three peg BEG(Source), AUX(AUXiliary) and st(Destination). 1) Move the top N – 1 disks from the Source to AUXiliary tower 2) Move the Nth disk from Source to Destination tower 3) Move the N – 1 disks from AUXiliary tower to Destination tower. Transferring the top N – 1 disks from Source to AUXiliary tower can again be thought of as a fresh problem and can be solved in the same manner.
  15. 15. Algorithm TOWER(N,BEG,AUX,END) If N=1 then BEG  END RETURN CALL(N-1,BEG,END,AUX) BEG  END CALL(N-1,AUX,BEG,END) BEG  END RETURN *Read Notes of this page
  16. 16. Tower of Hanoi( N= 3) 1. Move from BEG to END 2. Move from BEG to AUX 3. Move from END to AUX 4. Move from BEG to END 5. Move from AUX to BEG 6. Move from AUX to END 7. Move from BEG to END
  17. 17. Tower of Hanoi( N= 4) 1. Move from BEG to AUX 2. Move from BEG to END 3. Move from AUX to END 4. Move from BEG to AUX 5. Move from END to BEG 6. Move from END to AUX 7. Move from BEG to AUX
  18. 18. Tower of Hanoi( N= 4) 8. Move from BEG to END 9. Move from AUX to END 10. Move from AUX to BEG 11. Move from END to BEG 12. Move from AUX to END 13. Move from BEG to AUX 14. Move from BEG to END 15. Move from AUX to END
  19. 19. Presented by Akshat Saxena Year – 2nd Branch = CSE College – UIT RGPV
  20. 20. Thank You

×