You are on page 1of 13

DATA STRUCTURE

De-queue
Submitted To : Mrs. Niharika
Submitted By : Riya Rana
(bca second year)
Section “b”
DE-QUEUE

(DOUBLE ENDED
QUEUE)
Presentation title 3

DE-QUEUE

De-queue stands for Double Ended Queue. Deque


is a linear data structure where the insertion and
deletion operations are performed from both ends
(front end and rare end). We can say that deque is
a generalized version of the queue. Unlike the
queue, deque does not follow the FIFO rule.
Presentation title
4

INSERTION INSERTION

8 5 6 4
REMOVAL
REMOVAL

Representation of de-queue
Types of Dequeue:

• Input restricted dequeue

• Output restricted dequeue

Presentation title
• An input-restricted deque is one where deletion can be made from both ends, but
insertion can be made at one end only. An output-restricted deque is one where
insertion can be made at both ends, but deletion can be made from one end only.

Input restricted de- queue


6
• An output-restricted deque is one where insertion can be made at both ends, but deletion
can be made from one end only. Both the basic and most common list types in computing,
queues and stacks can be considered specializations of deques, and can be implemented using
deques. The basic operations on a deque are enqueue and dequeue on either end.

output restricted dequeue


7
Operations on a Deque
• There is the circular array implementation of deque.
• But in a linear array implementation, if the array is
full, no more elements can be inserted. In each of the
operations below, if the array is full, "overflow message"
is thrown.
• Before performing the following operations, these
steps are followed.
• Take an array (deque) of size n.
• Set two pointers at the first position and set front = -
1 and rear = 0

8
1. Insert at the Front
This operation adds an element at the front.
1. first we insert 3 at the front end.
2.Now we want to insert second element 5 at the front end
0 1 2 3
If front < 1,
reinitialize front = n-1(last
3
index)

3. Else,decrease front by 1
4. Add the new element 5
into 3rd index value.
F R
Front=-1
rear=-1(at this time queue
is empty)

(but when 3 is inserted in


5
the queue the index value
of f is 0 and the R is also 0) F
Insertion at the Rear
This operation adds an element at the rear.
1. Check if the array is full .
2. In the previous slide ,the index value of rear end is 0
3. Else increase rear by 1.
4. Add the new element 8 into 1st index value.

0 1 2 3

3 8 6 5

R
Deletion From The Front
1. CHECK IF THE DEQUE IS EMPTY.

2. IF THE DEQUE IS EMPTY (I.E. FRONT = -1), DELETION CANNOT BE PERFORMED (UNDERFLOW CONDITION).

3.IF THE DEQUE HAS ONLY ONE ELEMENT (I.E. FRONT = REAR), SET FRONT = -1 AND REAR = -1.

4.ELSE IF FRONT IS AT THE END (I.E. FRONT = N - 1), SET GO TO THE FRONT FRONT = 0.

5.ELSE, FRONT = FRONT + 1.

0 1 2 3
3 8 6 5
Deletion From The Rear
1. If The Deque Is Empty (I.E. Front = -1), Deletion Cannot Be Performed (Underflow Condition).
2. If The Deque Has Only One Element (I.E. Front = Rear), Set Front = -1 And Rear = -1, Else Follow The Steps Below.
3. If Rear Is At The Front (I.E. Rear = 0), Set Go To The Front Rear = N - 1.
4. Else, Rear = Rear - 1.
Thank
you

You might also like