Data Structure Questions and Answers-Towers of Hanoi

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

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
Data interpretation (DI) Questions answers
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
Biology Questions answers
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?
A
Madam
B
Dad
C
Malayalam
D
Maadam
Current affairs Questions answers
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
Journalism Questions answers
Question 4 Explanation: 
Stack is a convenient option as it involves pushing and popping of characters.

Question 5
Select the appropriate code which tests for a palindrome.
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
Reading comprehension Questions answers
Question 5 Explanation: 
Push all the characters in the input string to a stack, now pop them and append to a new string which is checked for equality with the original string.

There are 5 questions to complete.

 

 Download all FREE PDF Ebook >>>CLICK HERE<<<