Which among the following are the code to check the overflow and underflow conditions?
Implementing a push operation on stack using linked list is more time efficient than that of implementation using an array: ______
declare a stack of characters
while ( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while ( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}
What is output for input “gate2020”?
If the characters ‘z’, ‘y’, ‘x’, ‘w’ are placed in a queue (in the given order), and then removed one at a time, What will be the order after they are removed?
A + B * ( C ^ D - E)
Note: Precedence of ^(here, exponential operator) is same as that of *,/,% operators.
* - A / B C - / A K L
#include <stdio.h>
void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 1)
{
printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod);
return;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
int main()
{
int n = 5; // Number of disks
towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
return 0;
}
The optimal time of the Tower of Hanoi problem with n discs is
Note: Using recurrence method
#include <stdio.h>
void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
if (n == 0)
{
printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod);
return 0;
}
towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod);
towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}
int main()
{
int n = 5; // Number of disks
towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
return 0;
}
The total number of function calls made, in a tower of hanoi problem, when n=5 is__?
10 + 3 * 5 / (16 - 4)
6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
where ↑ is ‘to the power/exponential operator