0% completed
What is a Queue?
A queue is a linear data structure that follows the First-In, First-Out (FIFO) principle. This means that the first element added to the queue is the first one to be removed, just like a real-life queue where people wait in line for a service.
Real-World Analogy
Imagine you are waiting in line at a movie theater:
- The first person in the line is the first to get their ticket.
- When a new person arrives, they join at the end of the queue.
- The queue progresses in order, ensuring fairness in processing.
This FIFO behavior makes queues essential in computing, where tasks are processed in order of arrival.
Basic Terminology
To get comfortable with Queues, we need to grasp some key terms.
-
Enqueue: This is like adding a person to the end of our coffee shop line. In Queues, when we add an element at the end, we call it "Enqueue."
-
Dequeue: Remember how the first person in line gets their coffee first? Similarly, removing an element from the front of the Queue is called "Dequeue."
- Front: This is the start of the Queue, where the first element resides.
- Rear: This is the end of the Queue, where the last element is placed.
When you think about it, it's pretty simple, right? These are the basics, and once you've got a firm grip on them, everything else about Queues will fall into place!
Queue vs. Stack (Key Differences)
Feature | Stack (LIFO) | Queue (FIFO) |
---|---|---|
Order | Last-In, First-Out | First-In, First-Out |
Insertion | Push (at top) | Enqueue (at rear) |
Removal | Pop (from top) | Dequeue (from front) |
Usage | Backtracking, Recursion | Scheduling, BFS, Task Processing |
In the next lesson, we will explore queue operations (Enqueue, Dequeue, Peek, and IsEmpty) in detail.
.....
.....
.....
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible