Saturday, 21 September 2013

Stacks

The data structure required to evaluate a postfix expression is

A.
Queue


B.
Stack


C.
rray


D.
linked-list

Answer: Option B


2:
The postfix form of the expression
(A+B)
∗(C∗D-E)∗F/G is
A.
AB+CD ∗ E−FG/∗∗


B.
AB+CD ∗ E−F∗∗G/


C.
AB+CD ∗ E−∗F∗G/


D.
AB+CDE∗ −∗F∗G/





Answer: Option A

Explanation :

3:
What is the postfix form of the following prefix expression -A/B*C$DE
A.
ABCDE$*/-


B.
A-BCDE$*/-


C.
ABC$ED*/-


D.
A-BCDE$*/





Answer: Option A



4:
The data structure required to check whether an expression contains balanced parenthesis is
A.
Stack


B.
Queue


C.
Tree


D.
Array





Answer: Option A



5:
The postfix form of A*B+C/D is
A.
*AB/CD+


B.
AB*CD/+


C.
A*BC+/D


D.
ABCD+/ *





Answer: Option B


6:
Which of the following types of expressions does not require precedence rule when evaluated?
A.
Full parenthesized infix expression


B.
Prefix expression


C.
Partially parenthesized infix expression


D.
More than one of these





Answer: Option D



7:
The five items:A,B,C,D, and E are pushed in a stack, one after the other starting from A.The stack is popped four times and each element is inserted in a queue.Then two elements are deleted from the queue and pushed back on the stack.Now one item is popped from the stack.
The popped item is
A.
E



B.
B



C.
C



D.
D






Answer: Option D


In queue elements are deleted from front (FIFO) and in stacks elements are popped from top (LIFO)
stack

8:
If memory for the run-time stack is only 150 cells(words), how big can N be in Factorial(N) before encounterring stack overflow?
A.
24



B.
12



C.
26



D.
50





Answer: Option C

Explanation :
Given that, the size of a run time stack is of 150 cells (words). The arguments to be evaluate the factorial are placed on the stack. A function call is made to calculate the factorial. Subroutine is executed for each time the function call is made. Each funcall creates a stack frames of co words (Cells), 2 words for n, 2 words for program counter (PC) and 2 words for some other information.
The value of n should be such that, the size of stack should not exceed 150 cells. If we consider the value of n to be 26, it executes 25 procedure calls each of it with 6-word stack frame.
In this case totalnumber of words of stack space would be 150 (6 words × 25 procedure calls = 150) cells.
Therefore, value of n will be 26 is n! before encountering a stack overflow for the stack of size 150 cells (words)

9:
A postfix expression is merely the reverse of the prefix expression
A.
True


B.
False


C.



D.






Answer: Option A



10:
Following sequence of operations is performed on a stack push(1),push(2),pop, push(1),push(2)pop,pop,pop,push(2),pop.The sequence of poped out values are
A.
2,2,1,1,2


B.
2,2,1,2,2


C.
2,1,2,2,1


D.
2,1,2,2,2





Answer: Option A

Explanation :

11:
In eveluating the arithmetic expression 2*3-(4+5),using stacks to evaluate its equivalent postfix form, which of the following stack configuration is not possible?
A.
4 6


B.
5 4 6


C.
9 6


D.
9 3 2





Answer: Option D

Explanation :
The postfix equivallent is 2 3 * 4 5 + -.
For evaluating this using stack,starting from the left,we have to scan one by one, if it is an operand push.
If it is an operator, pop it twice,apply operator on the poppedout entries and push the result onto the stack.
If we follow this,we can find configuration in option(d)is not possible

12:
Stack A has the entries a,b,c(with a on top).
Stack B is empty.An entry popped out of stack A can be printed immediately or pushed to stack B.An entry popped out of the stack B can only be printed. In this arrangement, which of the following permutations of a,b,c are not possible?
A.
b a c


B.
b c a


C.
c a b


D.
c b a




Answer: Option C

Explanation :

13:
The expression which accesses the (ij)th entry of am x n matrix stored in column majorform is
A.
n x (i-1)+j


B.
m x (j-1)+i


C.
m x (n-j)+j


D.
n x (m-i)+j





Answer: Option B



14:
Stack can't be used to
A.
Evaluate an arithmetic expression in postfix form


B.
Implement recursion


C.
Convert a given arithmetic expression in infix form to its evaluate postfix form


D.
Allocate resources(like CPU)by the operating system





Answer: Option D



15:
Which of the following permutations can be obtained in the output(in the same order),using a stack assuming that the input is the sequence 1,2,3,4,5 in that order?
A.
3,4,5,1,2


B.
3,4,5,2,1


C.
1,5,2,3,4


D.
5,4,3,2,1





Answer: Option B


16:
Stack is useful for implementing
A.
Radix


B.
Breadth first search


C.
Recursion


D.
None of these





Answer: Option C



17:
If the sequence of operations- push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop, are performed on a stack, the sequenceof popped out values are
A.
2, 2, 1, 1, 2



B.
2, 2, 1, 2, 2



C.
2, 1, 2, 2, 1



D.
2, 1, 2, 2, 2






Answer: Option A



18:
Stack A has the eintries a, b, c (with a on top), Stack B is empty. An entry popped out of stack A can be printed immediately or pushed to stack B. An entry popped out of stack B can only be printed. In the arrangement, which of the following permutations of a, b, c is not possible?
A.
b a c



B.
b c a



C.
c a  b



D.
a b c






Answer: Option C



19:
The postfix equivalent of the prefix * + a b - c d is
A.
ab+cd-*



B.
ab cd + - *



C.
ab + cd * -



D.
ab + - cd *






Answer: Option A

Explanation :
The tree whose preorder traversal yields * + A B – C D, is given in fig 6.18. Writer the post-order traversal of the tree. That is the postfix form.

20:
Stacks cannot be used to
A.
eevaluate an arithmetic expression  in postfix form



B.
iumplemen recursion



C.
convert a given arithmetic expression in infix form to its equivalent postfix form



D.
allocate resources (like CPU) by the operating system






Answer: Option D

Explanation :
21:
The postifx expression for the infix expression
A + B* (C+D) / F + D*E is
A.
AB+CD + *F/ D+E*



B.
ABCD + *F / + DE* +



C.
A*B + CD / F* DE ++



D.
A + *BCD/ F* DE ++






Answer: Option B



22:
Stack is useful for implemeting
A.
breadth first search



B.
depth first search



C.
recursion



D.
Both (b) & (c)






Answer: Option D

Explanation :
Breadth first search  needs Queue for implementaion
 

23:
An item that is read as input can be either pushed to a stack and later popped and printed, or printed directly. Which of the following will be the output if the input is the sequence of items 1, 2, 3, 4, 5?
A.
3, 4, 5, 1, 2



B.
3, 4, 5, 2, 1



C.
1, 5, 2, 3, 4


D.
5, 4, 3, 1, 2






Answer: Option B

Explanation :