Shift 'n-1' disks from 'B' to 'C', using A. Shift 'n-1' disks from 'A' to 'B', using C. Step 7 : Shift first disk from 'A' to 'C'. The Tower of Hanoi is a mathematical puzzle containing 3 pillars/towers with n disks each of a different size/diameter. A larger disk cannot be placed on a smaller disk. There are two conditions that are to be followed while solving this problem. Step 6 : Shift second disk from 'B' to 'C'. Towers of Hanoi Problem is a famous puzzle to move N disks from the source peg/tower to the target peg/tower using the intermediate peg as an auxiliary holding peg. Step 3: Now move the n-1 discs which is present in pole2 to pole3. Step 1: Move (n-1) discs from pole1 to pole2 Step 2: Move the nth disc (last disc) from pole1 to pole3. Let’s assume there are ‘n’ discs and 3 poles (pole1, pole2, pole3). Step 5 : Shift first disk from 'B' to 'A'. We will be using Java Recursion to solve this problem and the below step will be performed. Step 4 : Shift third disk from 'A' to 'C'. The puzzle starts with the disk in ascending order of size in one pole, the smallest at the top. Step 3 : Shift first disk from 'C' to 'B'. The Tower of Hanoi is a classic game of logical thinking and sequential reasoning. It consists of three poles and a number of disks of different sizes which can slide onto any poles. Step 2 : Shift second disk from 'A' to 'B'. Step 1 : Shift first disk from 'A' to 'C'. Step 3 : Shift first disk from 'B' to 'C'. Step 2 : Shift second disk from 'A' to 'C'. Step 1 : Shift first disk from 'A' to 'B'.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |