Queues Flashcards
What is an Abstract Data Type (ADT)?
An ADT is a mathematical model for data types where the data type is defined by its behavior from the point of view of a user, specifically the operations that can be performed on it.
What is a queue?
A queue is an ADT that represents a collection of elements in which elements are added at one end (the rear) and removed from the other end (the front), following the First-In-First-Out (FIFO) principle.
True or False: In a queue, the last element added is the first one to be removed.
False
What are the primary operations of a queue?
The primary operations of a queue are enqueue (adding an element), dequeue (removing an element), and peek (viewing the front element without removing it).
Fill in the blank: In a queue, elements are added at the _____ and removed from the _____.
rear; front
What is the main difference between a queue and a stack?
A queue follows the FIFO principle, while a stack follows the Last-In-First-Out (LIFO) principle.
What is a circular queue?
A circular queue is a linear data structure that uses a single, fixed-size array in a circular way to efficiently utilize space by wrapping around.
True or False: A circular queue can lead to wasted space if not implemented correctly.
True
What is a priority queue?
A priority queue is an abstract data type where each element has a priority assigned to it, and elements are dequeued based on their priority rather than their order in the queue.
How does a priority queue differ from a regular queue?
In a priority queue, elements are removed based on priority, whereas in a regular queue, elements are removed in the order they were added.
What data structure is commonly used to implement a priority queue?
A binary heap is commonly used to implement a priority queue.
Fill in the blank: The operation to remove an element from a queue is called _____
dequeue
What is the initial condition of an empty queue?
The queue is said to be empty when there are no elements present in it.
What happens when you try to dequeue from an empty queue?
It typically results in an underflow error, indicating that there are no elements to remove.
What is the purpose of the peek operation in a queue?
The peek operation allows you to view the front element of the queue without removing it.
True or False: A queue can be implemented using arrays.
True
What is the main disadvantage of using an array to implement a queue?
The main disadvantage is that it can lead to wasted space if elements are removed from the front and the array size is fixed.
What is a dequeue?
A dequeue (double-ended queue) is a data structure that allows insertion and deletion of elements from both the front and rear ends.
How do you determine if a queue is full?
In a fixed-size array implementation, a queue is full when the number of elements equals the maximum capacity of the array.
What is a blocking queue?
A blocking queue is a type of queue that causes the thread to wait until the queue is not empty when trying to dequeue or until it is not full when trying to enqueue.
True or False: Queues can only store homogeneous data types.
False
What is the significance of the ‘front’ pointer in a queue implementation?
The ‘front’ pointer tracks the first element in the queue for efficient access during dequeue operations.
Fill in the blank: A queue is often used in _____ algorithms for managing tasks.
scheduling
What is the common application of a queue in computer science?
Queues are commonly used in scenarios like print job management, task scheduling, and breadth-first search algorithms.