# Data Structure Questions and Answers-Towers of Hanoi

## Data Structure Questions and Answers-Towers of Hanoi

 Question 1
Which data structure can be used suitably to solve the Tower of Hanoi problem?
 A Tree B Heap C Priority queue D Stack
Question 1 Explanation:
The Tower of Hanoi involves moving of disks 'stacked' at one peg to another peg with respect to the size constraint, it is conveniently done using stacks,

although it is also possible using priority queues. Since stack approach is widely used, the more suitable option would be 'd' stack.

 Question 2
Select the appropriate code for the recursive Tower of Hanoi problem.(n is the number of disks)
 A public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { System.out.println(start + " -> " + end); B public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { System.out.println(start + " -> " + end); C public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { System.out.println(start + " -> " + end); D None of the mentioned
Question 2 Explanation:
First transfer all the diska to the auxiliary and then to the end peg, this is achieved by making auxiliary peg as the end peg in the first recursive call, in the second recursive call, the auxiliary becomes the start peg from where the disks are transferred to the end peg.

 Question 3
Which among the following is not a palindrome?
Question 3 Explanation:
By definition, a palindrome is a string which is the same forward and backward, here, option d doesn't adhere to this definition.

 Question 4
Which data structure can be used to test a palindrome?
 A Tree B Heap C Stack D Priority queue
 A public static void main(String[] args) { System.out.print("Enter any string:"); Scanner in=new Scanner(System.in); String input < B public static void main(String[] args) { System.out.print("Enter any string:"); Scanner in=new Scanner(System.in); String input  C public static void main(String[] args) { System.out.print("Enter any string:"); Scanner in=new Scanner(System.in); String input  D None of the mentioned