Question:

The elements to be inserted in the Deque are 10, 20, 30, 40, 50, 60, starting from 10.
What will be the sequence of elements after the following operations are performed on a Deque:
INSERTFRONT(), INSERTREAR(), INSERTFRONT(), DELETEREAR(), DELETEFRONT(), INSERTFRONT(), INSERTREAR(), INSERTFRONT()
A. 10
B. 40
C. 50
D. 60
Choose the correct answer from the options given below:

Show Hint

Trace Deque operations using a simple list on paper:
- Add/remove on the left for FRONT operations.
- Add/remove on the right for REAR operations.
Keep a pointer index on your input sequence (10, 20, 30...) to remember which number is being enqueued next!
Updated On: Jun 11, 2026
  • D, B, A, C
  • B, D, A, C
  • B, A, C, D
  • D, C, A, B
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation


Step 1: Understanding the Question:

The question asks to trace the state of a Double-Ended Queue (Deque) after executing a specific sequence of insertion and deletion operations. The sequence of incoming input elements is 10, 20, 30, 40, 50, 60, processed in order.

Step 2: Key Operational Principles of a Deque:

- A Deque (Double-Ended Queue) allows insertion and deletion of elements from both ends (Front and Rear).
- INSERTFRONT(): Adds an element to the left (beginning) of the queue.
- INSERTREAR(): Adds an element to the right (end) of the queue.
- DELETEFRONT(): Removes the leftmost element from the queue.
- DELETEREAR(): Removes the rightmost element from the queue.

Step 3: Detailed Step-by-Step Execution Trace:

- We begin with an empty Deque: []
- The incoming elements are: 10, then 20, then 30, then 40, then 50, then 60.
- 1. INSERTFRONT() $\rightarrow$ Inserts 10 at the front:
Deque state: [10]
- 2. INSERTREAR() $\rightarrow$ Inserts 20 at the rear:
Deque state: [10, 20]
- 3. INSERTFRONT() $\rightarrow$ Inserts 30 at the front:
Deque state: [30, 10, 20]
- 4. DELETEREAR() $\rightarrow$ Removes the rear element (20):
Deque state: [30, 10]
- 5. DELETEFRONT() $\rightarrow$ Removes the front element (30):
Deque state: [10]
- 6. INSERTFRONT() $\rightarrow$ Inserts 40 at the front:
Deque state: [40, 10]
- 7. INSERTREAR() $\rightarrow$ Inserts 50 at the rear:
Deque state: [40, 10, 50]
- 8. INSERTFRONT() $\rightarrow$ Inserts 60 at the front:
Deque state: [60, 40, 10, 50]
- The final sequence of elements in the Deque is: [60, 40, 10, 50].
- Now let us map these values to the corresponding variable labels:
- 60 is represented by D.
- 40 is represented by B.
- 10 is represented by A.
- 50 is represented by C.
- This translates to the sequence: D, B, A, C.

Step 4: Final Answer:

The final sequence of elements in the Deque is D, B, A, C.
Hence, option (A) is the correct choice.
Was this answer helpful?
0
0