General

Computer Science

  1. 1. Introduction to Computer Science
  2. Legacy Course

  3. Introduction to Computer Science
  4. History of Computer Science
  5. Fundamentals of Computer Science
  6. Algorithms
  7. Data Structures
  8. Programming Concepts
  9. Web Development
  10. Databases and SQL
  11. Networking and Security
  12. Artificial Intelligence and Machine Learning
  13. Mobile App Development
  14. Game Development
  15. Future of Computer Science
  16. Careers in Computer Science

Queues

Module Progress
0 / 52 Lessons
0%
Learning

A queue is a linear data structure 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 learning with Knowness

Sign up to access the full lesson, predicted grades, revision tools, progress tracking, and more.

Create a free account