Queue Data Structure

16 views Queue in DSA

Queue Data Structure - Interactive Learning

Master Queue - DSA Learning Platform 📋 Master Queue Linear DS FIFO Principle Learn Queue operations with interactive visualizations - Enqueue, Dequeue, and more! 📖 Understanding Queue Introduction FIFO Principle Types of Queue Operations Applications What is a Queue? A Queue is a linear data structure that follows the FIFO (First In First Out) principle. Think of it like a line of people waiting at a ticket counter - the first person to arrive is the first one to be served. Unlike a stack where operations happen at one end, a queue has two ends: the front (where elements are removed) and the rear (where elements are added). Queues are fundamental in computer science and are used extensively in scheduling algorithms, BFS traversal, buffering, and managing shared resources. 🔑 Key Properties FIFO (First In First Out) order Two ends: Front and Rear Insertion at Rear (Enqueue) Deletion from Front (Dequeue) O(1) time for all operations Linear data structure FIFO Principle FIFO stands for First In, First Out. This means the element that enters the queue first will be the first one to leave. First element added → First element removed Real-world examples of FIFO: 🎫 Ticket Queue: First person in line gets served first 🖨️ Print Queue: First document sent prints first 📞 Call Center: First caller gets answered first 🚗 Traffic: First car at signal goes first 📍 FIFO Visualization Enqueue (Add to Rear): ┌─────┐ New Element ──────────────► │ E │ └─────┘ │ ▼ ┌─────┬─────┬─────┬─────┬─────┬─────┐ │ A │ B │ C │ D │ E │ │ └─────┴─────┴─────┴─────┴─────┴─────┘ ▲ ▲ │ │ FRONT REAR Dequeue (Remove from Front): ┌─────┐ │ A │ ──────────────► Removed └─────┘ Types of Queue There are several variations of the queue data structure, each designed for specific use cases: 📋 Simple Queue Basic FIFO queue with front and rear pointers 🔄 Circular Queue Rear connects back to front, efficient space usage ⭐ Priority Queue Elements served based on priority, not arrival order ↔️ Double-ended Queue Insert/delete from both front and rear (Deque) 🔄 Circular Queue Advantage Solves memory wastage problem Rear wraps around to use empty front slots Used in: CPU scheduling, memory management Formula: next = (current + 1) % size ⭐ Priority Queue Use Cases Dijkstra's shortest path Huffman coding Operating system scheduling Event-driven simulation Queue Operations 📥 Enqueue Add an element to the rear of the queue O(1) 📤 Dequeue Remove an element from the front of the queue O(1) 👁️ Peek / Front View the front element without removing it O(1) ❓ isEmpty Check if the queue is empty O(1) 📏 Size Get the number of elements in queue O(1) 🈵 isFull Check if queue is full (array implementation) O(1) 📍 Operation Steps Enqueue(X): 1. Check if queue is full 2. If rear == size-1, overflow 3. Increment rear 4. queue[rear] = X Dequeue(): 1. Check if queue is empty 2. If front > rear, underflow 3. temp = queue[front] 4. Increment front 5. Return temp Peek(): 1. Check if queue is empty 2. Return qu...

Subject: Data Structures with Animation | Chapter: Queue in DSA

Loading animation...

Up to Top