Skip to content
ExamHope Logo

examhope

Primary Menu
  • Digital Logic
    • Arithmetic Operations
    • Asynchronous/Ripple Counters
    • Basic Gates
    • Boolean Algebraic Theorems
    • Codes
  • Data Structures
    • Binary Heaps
    • Binary Search
    • Binary Search Trees
    • Binary Tree
    • Binary Tree Sort
    • Bipartite Graphs
    • Complete Graph
  • Theory of Computation
    • Finite Automata
    • Finite Automaton First Example
  • Current Affairs
    • Sports News
    • Tech News
    • Bollywood News
    • Daily News
  • Database
  • Computer Network
  • Computer Organization and Architecture
  • C Language
  • Operating Systems
  • Software Engineering
  • Theory of Computation
  • About us
  • Contact Us
  • Privacy Policy
  • DMCA Policy
  • Terms and Conditions
  • Home
  • IT
  • Data Structures
  • Deque — Data Structures
  • Deque
  • Data Structures

Deque — Data Structures

examhopeinfo@gmail.com November 11, 2025 4 minutes read
Deque

Deque

What is a Deque?

The word Deque stands for Double-Ended Queue.
As the name says, it’s a queue where you can add or remove elements from both ends — the front and the rear.

In a normal queue, we can:

  • Insert (enqueue) only from the rear
  • Delete (dequeue) only from the front

But in a deque, we can do both operations from either side.
It’s like having a queue that’s open at both ends!


🎯 Real-Life Analogy

Imagine a line of people waiting to get into a movie theater.
In a normal queue, new people join from the back, and people enter the theater from the front.

Now imagine a special line where people can enter or leave from both ends — maybe there are two doors.
That’s what a deque is!


⚙️ Basic Structure of a Deque

A deque can be visualized as a row of boxes (like memory slots).
You can insert or remove data from the left (front) or the right (rear).

Here’s a simple diagram:

 FRONT                                 REAR
   ↓                                     ↓
+-----+-----+-----+-----+-----+
|     | 10  | 20  | 30  |     |
+-----+-----+-----+-----+-----+
   ↑                       ↑
Insert/Delete         Insert/Delete

So you have four possible operations:

  1. Insert Front – Add an element at the front
  2. Insert Rear – Add an element at the rear
  3. Delete Front – Remove an element from the front
  4. Delete Rear – Remove an element from the rear

🧩 Types of Deques

There are two main types of deques depending on how we allow insertions and deletions:


🔹 1. Input-Restricted Deque

  • Insertion is allowed only at one end (say, rear)
  • Deletion is allowed at both ends

✅ Example:
You can only add new people at the back of the line,
but you can remove them either from the front or back.


🔹 2. Output-Restricted Deque

  • Insertion is allowed at both ends
  • Deletion is allowed only at one end (say, front)

✅ Example:
People can enter the line from either door,
but they can leave only through one exit.


🧮 Example of Deque Operations

Let’s understand how elements move in a deque step by step.

Step 1: Start Empty

[   ]  [   ]  [   ]  [   ]

Step 2: Insert 10 at Rear

[10]  [   ]  [   ]  [   ]

Step 3: Insert 20 at Rear

[10]  [20]  [   ]  [   ]

Step 4: Insert 5 at Front

[5]  [10]  [20]  [   ]

Step 5: Delete from Rear

[5]  [10]  [   ]  [   ]

So, elements can freely move in and out from both directions.


🧱 Diagram of Deque Operations

Here’s a simple text-based visualization:

Insert Front  → ←  Delete Front
+--------------------------------+
|  5  | 10 | 20 | 30 | 40 |
+--------------------------------+
↑                               ↑
Delete Rear           Insert Rear

You can see both ends are active — this is what makes the deque double-ended.


💡 Why Use a Deque?

Deques are more flexible than simple queues or stacks.
They can act as:

  • A queue (insert at rear, delete at front)
  • A stack (insert and delete from the same end)
  • Or something in between, depending on what you need.

They are especially useful when you need both LIFO (Last In, First Out) and FIFO (First In, First Out) behaviors in the same program.


⚙️ Common Implementations

Deques can be implemented in several ways:

MethodDescription
Array-based DequeUses a fixed-size array. Simple but has limited capacity.
Linked List-based DequeUses nodes linked to each other. Size is dynamic and flexible.
Circular ArrayCommon in real systems; wraps around the ends to reuse space efficiently.

🧠 Example in Pseudocode

Here’s a small example of how a deque might work:

insertFront(x):
    if deque is full:
        print "Overflow"
    else:
        front = (front - 1 + size) % size
        deque[front] = x

insertRear(x):
    if deque is full:
        print "Overflow"
    else:
        rear = (rear + 1) % size
        deque[rear] = x

deleteFront():
    if deque is empty:
        print "Underflow"
    else:
        front = (front + 1) % size

deleteRear():
    if deque is empty:
        print "Underflow"
    else:
        rear = (rear - 1 + size) % size

🌍 Real-Life Applications

You might not realize it, but deques are everywhere in computer systems:

  1. 🧮 Job Scheduling: Tasks can be added or removed from either end based on priority.
  2. 🔁 Undo/Redo Feature: Recent actions are added or removed from both ends.
  3. 🖼 Browser History: Navigate forward and backward easily.
  4. 🧭 Palindrome Checking: Compare characters from both ends of a string.

🧭 Summary

OperationFrontRear
Insert Front✅❌ or ✅
Delete Front✅❌ or ✅
Insert Rear✅✅
Delete Rear✅✅
  • A Deque is like a queue, but smarter — you can work from both sides.
  • It combines the power of stacks and queues in one structure.
  • Depending on your needs, it can be input-restricted or output-restricted.
  • It’s widely used in programming, operating systems, and algorithms.

About the Author

examhopeinfo@gmail.com

Administrator

Visit Website View All Posts

Post navigation

Previous: Priority Queue — Data Structures
Next: Linked Implementation of Stacks — Data Structures

Related News

Linked Representation
  • Linked Representation of a Graph
  • Data Structures

Linked Representation of a Graph

examhopeinfo@gmail.com November 14, 2025 0
Path Matrix
  • Path Matrix
  • Data Structures

Path Matrix

examhopeinfo@gmail.com November 14, 2025 0
Adjacency Matrix
  • Adjacency Matrix
  • Data Structures

Adjacency Matrix

examhopeinfo@gmail.com November 14, 2025 0

Recent Posts

  • Vivo X200: जाने कितनी कम कीमत पर मिल रहा ये 9400 मिडिया टेक प्रोसेसर वाला स्मार्टफोन
  • Samsung Galaxy S25 Plus पर मिल रही भारी छूट ,जाने सेल प्राइस
  • AI के इस ज़माने में कैसे बिजली बचा रहे हैं यह स्मार्ट प्लग?
  • क्या है यह GhostPairing Scam और बिना पासवर्ड और सिम के क्यों हो रहा है व्हाट्सप्प अकाउंट हैक
  • Leica कैमरे के साथ जल्द लॉन्च हो सकता है Xiaomi Ultra 17

At ExamHope, we understand that preparing for exams can be challenging, overwhelming, and sometimes stressful. That’s why we are dedicated to providing high-quality educational resources, tips, and guidance to help students and aspirants achieve their goals with confidence. Whether you are preparing for competitive exams, school tests, or professional certifications, ExamHope is here to make your learning journey smarter, easier, and more effective.

Quick links

  • About us
  • Contact Us
  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
  • DMCA Policy

Category

  • Computer Network
  • Computer Organization and Architecture
  • Data Structures
  • C Language
  • Theory of Computation
  • Database

You may have missed

Vivo X200 Price Drop
  • IT
  • Current Affairs
  • Tech News

Vivo X200: जाने कितनी कम कीमत पर मिल रहा ये 9400 मिडिया टेक प्रोसेसर वाला स्मार्टफोन

examhopeinfo@gmail.com December 23, 2025 0
Samsung Galaxy S25 Plus
  • IT
  • Current Affairs
  • Tech News

Samsung Galaxy S25 Plus पर मिल रही भारी छूट ,जाने सेल प्राइस

examhopeinfo@gmail.com December 22, 2025 0
Electricity bill saving Smart Plug
  • IT
  • Current Affairs
  • Tech News

AI के इस ज़माने में कैसे बिजली बचा रहे हैं यह स्मार्ट प्लग?

examhopeinfo@gmail.com December 21, 2025 0
Ghost Pairing Scam on Whatsapp
  • IT
  • Current Affairs
  • Tech News

क्या है यह GhostPairing Scam और बिना पासवर्ड और सिम के क्यों हो रहा है व्हाट्सप्प अकाउंट हैक

examhopeinfo@gmail.com December 21, 2025 0
Copyright © All rights reserved for ExamHope. | MoreNews by AF themes.
Go to mobile version