#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Queues

Deque in Data Structure

A Deque (Double-Ended Queue) is a linear data structure that allows insertion and removal of elements from both the front and the rear ends, unlike a regular queue which only allows insertion at the rear and removal at the front.

Core Operations

  • addFront(item) — insert an element at the front.
  • addRear(item) — insert an element at the rear.
  • removeFront() — remove and return the front element.
  • removeRear() — remove and return the rear element.
  • isEmpty() / size() — utility operations.
from collections import deque

dq = deque()
dq.append(10)        # addRear
dq.appendleft(5)      # addFront
dq.pop()              # removeRear -> 10
dq.popleft()          # removeFront -> 5

Types of Deques

  • Input-restricted deque: insertion allowed only at one end, deletion at both ends.
  • Output-restricted deque: deletion allowed only at one end, insertion at both ends.

Complexity

OperationTime
Insert/Remove at front or rearO(1)
Access by indexO(n)

Applications

  • Implementing both stacks and queues using a single structure.
  • Sliding window problems (e.g., maximum in every window of size k).
  • Undo operations that need access from both ends of a history list.

Ready to master Data Structures & Algorithms?

Learn DSA hands-on with mentor-led sessions, real interview practice, and placement support.

Explore Course