Stack


Q21.

Consider the following sequence of operations on an empty stack. push(54); push(52); pop(); push(55); push(62); s=pop(); Consider the following sequence of operations on an empty queue. enqueue(21); enqueue(24); dequeue(); enqueue(28); enqueue(32); q=dequeue(); The value of s+q is ___________.
GateOverflow

Q22.

A function f defined on stacks of integers satisfies the following properties. f(\emptyset) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i. If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?
GateOverflow

Q23.

Convert the pre-fix expression to in-fix -^{*}+A B C^{*}-D E+F G
GateOverflow

Q24.

Choose the correct alternatives (more than one may be correct) and write the corresponding letters only: The following sequence of operations is performed on a stack: PUSH (10), PUSH (20), POP, PUSH (10), PUSH (20), POP, POP, POP, PUSH (20), POP The sequence of values popped out is
GateOverflow

Q25.

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 sequence of popped out values
GateOverflow

Q26.

Choose the equivalent prefix form of the following expression(a+(b-c))^{\star}((d-e) /(f+g-h))
GateOverflow

Q27.

A stack is implemented with an array of { }^{\prime} A[0 \ldots N-1]^{\prime} and a variable \text { 'pos'. } The push and pop operations are defined by the following code. push (x) A[pos] <- x pos <- pos -1 end push pop() pos <- pos+1 return A[pos] end popWhich of the following will initialize an empty stack with capacity N for the above implementation?
GateOverflow

Q28.

Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?
GateOverflow

Q29.

The result evaluating the postfix expression 10 5 + 60 6 / * 8 - is
GateOverflow

Q30.

Consider the following C program: #include < stdio.h > #define EOF -1 void push (int); /* push the argument on the stack */ int pop (void); /* pop the top of the stack */ void flagError (); int main () { int c, m, n, r; while ((c = getchar ()) != EOF) { if (isdigit (c) ) push (c); else if ((c == '+') || (c == '*')) { m = pop (); n = pop (); r = (c == '+') ? n + m : n*m; push (r); } else if (c != ' ') flagError (); } printf("% c", pop ()); } What is the output of the program for the following input?5 2 * 3 3 2 + * +
GateOverflow