Stack · Data Structures
13 questions · asked in 8 of 27 years (2000–2026)
MCQ 10 · MSQ 2 · NAT 11-mark 11 · 2-mark 2
2000Questions per year2026
Questions 11–13 of 13
A single array A[1...MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top 2 (top1 top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for "stack full" is
Answer: (D)
Stack 1 grows up from index 1, and stack 2 grows down from index MAXSIZE. When both are empty, and .
To use the space efficiently, either stack must be able to take any free cell, so one stack can grow large while the other stays small. The array is full only when there is no free cell between the two tops, which means the tops are next to each other: , that is .
(A) is true only when each stack holds exactly half, so an uneven split that fills the array is not detected. (B) says , which can hold while free cells remain between the tops. (C) calls the array full when stack 1 reaches half of it, even if stack 2 is empty, or when stack 2 has just one element, so it wastes space.
Answer: (D)
To use the space efficiently, either stack must be able to take any free cell, so one stack can grow large while the other stays small. The array is full only when there is no free cell between the two tops, which means the tops are next to each other: , that is .
(A) is true only when each stack holds exactly half, so an uneven split that fills the array is not detected. (B) says , which can hold while free cells remain between the tops. (C) calls the array full when stack 1 reaches half of it, even if stack 2 is empty, or when stack 2 has just one element, so it wastes space.
Answer: (D)
Let S be a stack of size n 1. Starting with the empty stack, suppose we push the first n natural numbers in sequence, and then perform n pop operations. Assume that Push and Pop operation take X seconds each , and Y seconds elapse between the end of the one such stack operation and the start of the next operation. For m 1, define the stack-life of m as the time elapsed from the end or Push (m) to the start of the pop operation that removes m from S . The average stack-life of an element of this stack is
Answer: (C)
Let us write the stack-life of the element as . The element stays in the stack until elements are pushed and popped. We add one more for the gap between the push of the element and the push of the element. So,
where
The average stack-life is then,
Correct Answer:
where
The average stack-life is then,
Correct Answer:
To evaluate an expression without any embedded function calls
Answer: (A)
An expression with no function calls, for example , can be evaluated in two steps that run one after the other:
Step 1: Convert infix to postfix using a stack. The stack holds the operators. At the end of this step the stack is empty.
Step 2: Evaluate the postfix expression using a stack. The stack holds the operands. This is the same stack, reused after step 1 has finished.
So one stack is enough. (B) is not needed, because the two steps are never running at the same time. (C) is wrong because the height of the expression tree does not decide how many stacks are needed. (D) is wrong because a stack is much less than a Turing machine and is already enough.
Answer: (A)
Step 1: Convert infix to postfix using a stack. The stack holds the operators. At the end of this step the stack is empty.
Step 2: Evaluate the postfix expression using a stack. The stack holds the operands. This is the same stack, reused after step 1 has finished.
So one stack is enough. (B) is not needed, because the two steps are never running at the same time. (C) is wrong because the height of the expression tree does not decide how many stacks are needed. (D) is wrong because a stack is much less than a Turing machine and is already enough.
Answer: (A)
Keep practising