Skip to content
Azhimathi Mayam logoDSA Study HubPCCST303 · KTU · S3
B.Tech S3 (S) Examinations May 2026 (2024 Scheme)QP 06PCCST303112504Part B · Q9b4 marksCO1Module 1asked in 2 papers

Question 9b

Write algorithm for various deletion operations of double ended queue using array.

Topics: Double-ended queues

Watch this exact question run

Loading visualizer…

Solution

Assumptions:
  • Circular array dq[0 … MAX−1]; front = rear = −1 when empty.
algorithm
Algorithm DeleteFront()
1. if front = −1 then print "Underflow"; return
2. item ← dq[front]
3. if front = rear then front ← −1; rear ← −1
4. else front ← (front + 1) mod MAX
5. return item

Algorithm DeleteRear()
1. if front = −1 then print "Underflow"; return
2. item ← dq[rear]
3. if front = rear then front ← −1; rear ← −1
4. else rear ← (rear − 1 + MAX) mod MAX
5. return item
Example: MAX = 4checked by code
OperationResultfront, rearArray (index 0 … 3)Front → rear
insertRear(10)ok0, 0[10 _ _ _]10
insertRear(20)ok0, 1[10 20 _ _]10 20
insertFront(5)ok3, 1[10 20 _ 5]5 10 20
deleteRearremoved 203, 0[10 _ _ 5]5 10
deleteFrontremoved 50, 0[10 _ _ _]10
deleteRearremoved 10-1, -1[_ _ _ _]empty
deleteFrontUNDERFLOW-1, -1[_ _ _ _]empty

MAX = 4. “_” marks a slot that holds no live element.

How to write it in the exam

  • Both deletions first check empty: front == −1.
  • Deleting the only element (front == rear) resets front = rear = −1.
  • Delete at front: front = (front + 1) % MAX. Delete at rear: rear = (rear − 1 + MAX) % MAX.
How this answer was verified
  • tests/linear-expression.test.ts
  • deque_array.c matches the engine on 200 random cases

Similar questions