Queue Flashcards
What is a queue in C++?
A queue is a linear data structure that follows the First In First Out (FIFO) principle.
True or False: In a queue, the last element added is the first to be removed.
False
What is the primary purpose of a queue?
To manage data in a way that allows for efficient processing of elements in the order they were added.
Which data structure is commonly used to implement a queue in C++?
A linked list.
Fill in the blank: In a linked list implementation of a queue, each node contains data and a ________ to the next node.
pointer
What are the two main operations of a queue?
Enqueue (adding an element) and Dequeue (removing an element).
What does the enqueue operation do?
It adds an element to the back of the queue.
What does the dequeue operation do?
It removes and returns the front element of the queue.
What is the time complexity of the enqueue operation in a linked list queue?
O(1)
What is the time complexity of the dequeue operation in a linked list queue?
O(1)
True or False: A queue can be implemented using an array.
True
What is a common issue with using arrays for queue implementation?
Fixed size and potential overflow.
What does it mean for a queue to be ‘empty’?
It means there are no elements in the queue.
How can you check if a queue implemented with a linked list is empty?
By checking if the head pointer is null.
Fill in the blank: The front element of the queue is accessed through the ________ pointer.
head
What is the role of the rear pointer in a linked list queue?
It points to the last element in the queue.
What happens if you try to dequeue from an empty queue?
It can lead to an underflow condition or an error.
True or False: A queue can grow and shrink dynamically when implemented with a linked list.
True
What is the purpose of a destructor in a linked list queue implementation?
To free up memory by deleting all nodes when the queue is no longer in use.
What is the significance of the ‘Node’ structure in a linked list queue?
It represents each element in the queue, containing data and a pointer to the next node.
How do you implement the enqueue operation in a linked list queue?
Create a new node, set its next pointer to null, and link it to the current rear node.
What should you do with the rear pointer after an enqueue operation?
Update the rear pointer to point to the new node.
What is a circular queue?
A queue where the last position is connected back to the first position, forming a circle.
True or False: A circular queue can help avoid the problem of wasted space in a linear queue.
True