DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Tools
  3. Algorithm Visualizer
  4. Queue (Enqueue/Dequeue)

Queue (Enqueue/Dequeue)

Data Structureseasy#13

FIFO data structure — enqueue at rear, dequeue from front

Ready

Step 1 of 0

Speed

Input Data

Comma-separated numbers (0-999). Min 2 values.

Algorithm Code

1class Queue {
2 constructor() { this.items = []; }
3 enqueue(item) { this.items.push(item); }
4 dequeue() { return this.items.shift(); }
5 front() { return this.items[0]; }
6 isEmpty() { return this.items.length === 0; }
7 size() { return this.items.length; }
8}
Best

O(1)

Average

O(1)

Worst

O(1)

Space

O(n)

About Queue (Enqueue/Dequeue)

A Queue is a FIFO (First In, First Out) data structure. Elements are added at the rear (enqueue) and removed from the front (dequeue). Used in BFS traversal, task scheduling, print spoolers, message queues (Kafka, RabbitMQ), and rate limiting.

Time Complexity: Best: O(1), Average: O(1), Worst: O(1). Space: O(n).

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.