Which of the following uses only increment operations for adding and removing…

2025

Which of the following uses only increment operations for adding and removing element at either end?

  1. A.

    Queues

  2. B.

    Stacks

  3. C.

    Priority Queues

  4. D.

    Deques

Attempted by 430 students.

Show answer & explanation

Correct answer: D

Answer: Deques — a deque (double-ended queue) supports insertion and removal at both the front and the back.

Why this is correct:

  • Definition: A deque allows adding and removing elements at both ends (front and back).

  • Typical implementation note: Using a circular array with head and tail indices makes these operations efficient. Example index updates (modulo capacity): push_back increments the tail index, pop_back decrements the tail, push_front decrements the head, and pop_front increments the head. All index changes are simple pointer arithmetic.

  • Why other structures are incorrect:

    • Queue: supports insertion at the rear and removal from the front only (FIFO), not both ends.

    • Stack: supports insertion and removal at a single end (the top) only.

    • Priority Queue: removal depends on element priority and requires comparisons and reordering (e.g., heap operations), not just simple end-based pointer updates.

Takeaway: The double-ended nature of deques is what enables adding and removing at either end; implementations use simple index arithmetic to make these operations efficient.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Coding For Placement