General
Computer Science
-
1. Introduction to Computer Science
-
Introduction to Computer Science
-
History of Computer Science
-
Fundamentals of Computer Science
-
Algorithms
-
Data Structures
-
Programming Concepts
-
Web Development
-
Databases and SQL
-
Networking and Security
-
Artificial Intelligence and Machine Learning
-
Mobile App Development
-
Game Development
-
Future of Computer Science
-
Careers in Computer Science
Legacy Course
Queues
A queue is a linear data structureThe organisation and order of information in a text. that follows the First In First Out (FIFO) principle. It consists of a collection of elements, where the first element added to the queue is the first one to be removed. The front of the queue is the element that is most likely to be removed next, and the rear of the queue is where new elements are added.
There are three main operations that can be performed on a queue: enqueue, dequeue, and peek.
- The enqueue operation adds an element to the rear of the queue.
- The dequeue operation removes the front element from the queue.
- The peek operation returns the front element of the queue without removing it.
Queues can be represented using an array or a linked list. The array representation is a fixed-size array and the linked list representation is a singly linked list with a head pointing to the front of the queue and a tail pointing to the rear of the queue.
Queues are commonly used in a wide range of applications, some of the most common uses are:
Scheduling: Queues are used in scheduling algorithms to keep track of the order in which tasks need to be executed. The tasks that need to be executed first are added to the front of the queue, and as tasks are completed, they are removed from the front of the queue.
Simulations: Queues are used in simulations to model real-life scenarios such as waiting lines, traffic, and network packets. In these scenarios, elements are added to the rear of the queue, and as they are processed, they are removed from the front of the queue.
Breadth-first search: In breadth-first search algorithm, a queue is used to keep track of the nodes that need to be visited. The first visited node is dequeued, and its children are enqueued to be visited later.
Continue the lesson
This section is available to learners with course access. Continue learning with Knowness to unlock the full explanation, examples, revision tools, and progress tracking.
The remaining lesson content includes further guided explanation, important learning points, and supporting interactive material designed to help you understand and revise this topic.
Unlock this topic to view the full activity, worked examples, common mistakes, and additional revision support.
More content available
Knowness lessons are structured to build understanding step by step. Create an account or upgrade your access to continue from this point.
This preview does not include the hidden lesson text, answers, explanations, or embedded interactions.
Continue learning with Knowness
Sign up to access the full lesson, predicted grades, revision tools, progress tracking, and more.
Create a free account