Exams › GATE › Technical
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?
- A queue cannot be implemented using this stack.
- A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.
- A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.
- A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.
Correct answer: A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.
Solution
With a REVERSE-capable stack you can implement a queue: ENQUEUE = REVERSE, PUSH, REVERSE (three instructions) inserts at the bottom, and DEQUEUE = POP (one instruction) removes the front. Thus option 2 is correct; ENQUEUE and DEQUEUE cannot both be single instructions, so the stored answer (idx 3) is wrong.
Related GATE Technical questions
- The dual of a Boolean function F(x1, x2,..., xn, +, ·, ') written as FD is the same expression as that of F with + and · swapped. F is said to be self-dual if F = FD. The number of self-dual functions with Boolean variables is
- Consider the following function
double f(double x) {
if( abs(x*x - 3) < 0.01) return x;
else return f(x/2 + 1.5/x);
}
Give a value q (to 2 decimals) such that f(q) will return q.
- The three-dimensional state of stress at a point is given by σ = [[10, 0, 0],[0, 40, 0],[0, 0, 0]] MPa. The maximum shear stress at the point is
- A 2 m wide strip footing is founded at a depth of 1.5 m below the ground level in a homogeneous pure clay bed. The clay bed has unit cohesion of 40 kPa. Due to seasonal fluctuations of water table from peak summer to peak monsoon period, the net ultimate bearing capacity of the footing, as per Terzaghi’s theory, will
- Consider the statements P and Q.
P: Soil particles formed by mechanical weathering, and close to their origin are generally subrounded.
Q: A activity of the clay physically signifies its swell potential.
Which one of the following options is CORRECT?
- The number of degrees of freedom for a natural open channel flow with a mobile bed is
⚔️ Practice GATE Technical free + battle 1v1 →