192 views
2 2 votes

A double-ended queue (DEQUE) supports insertion and deletion at both ends $(f$ for front, $r$ for rear$)$. If we want to implement a STACK using this DEQUE, which of the following pairs of operations would correctly simulate the $\verb|PUSH(X)|$ and $\verb|POP()|$ behavior?

  1. $\verb|INSERT_FRONT(X)|$ AND $\verb|DELETE_REAR()|$
     
  2. $\verb|INSERT_REAR(X)|$ AND $\verb|DELETE_REAR()|$
     
  3. $\verb|INSERT_REAR(X)|$ AND $\verb|DELETE_FRONT()|$
     
  4. $\verb|INSERT_FRONT(X)|$ AND $\verb|INSERT_REAR()|$

1 Answer

1 1 vote

(A) INSERT_FRONT / DELETE_REAR: This is FIFO behavior (Queue).

(B) INSERT_REAR / DELETE_REAR: This is LIFO behavior. The most recent element added to the rear is the first to be removed from the rear. CORRECT.

(C) INSERT_REAR / DELETE_FRONT: This is FIFO behavior (Queue).

(D) INSERT_FRONT / INSERT_REAR: These are two insertion operations; no deletion is defined to simulate a POP.

Answer:
Position:
Show:

Related questions

3 3 votes
2 2 answers
348
348 views
GO Classes asked Feb 27
348 views
Suppose we convert a balanced Binary Search Tree (BST) containing $n$ elements into a Sorted Doubly Linked List (DLL) in-place (without using extra memory for new nodes)....
0 0 votes
1 1 answer
216
216 views
GO Classes asked Feb 27
216 views
A hash table of size $M=11$ uses the hash function $h(k)=k \bmod 11$. QUADRATIC PROBING is used for collision resolution with the probing function $h(k, i)=\left(h(k)+i^2...
2 2 votes
1 1 answer
196
196 views
GO Classes asked Feb 27
196 views
Let $G=(V, E)$ be a directed graph with source vertex $s$. We run DIJKSTRA'S ALGORITHM to find the shortest paths. During the execution, the "Relaxation" step is performe...
1 1 vote
1 1 answer
156
156 views
GO Classes asked Feb 27
156 views
Consider the QUICKSORT algorithm applied to an array of $n$ distinct elements. Let the pivot always be chosen as the MEDIAN of the array. What is the recurrence relation ...