Queue Flashcards

1
Q

What is a queue in C++?

A

A queue is a linear data structure that follows the First In First Out (FIFO) principle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: In a queue, the last element added is the first to be removed.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the primary purpose of a queue?

A

To manage data in a way that allows for efficient processing of elements in the order they were added.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which data structure is commonly used to implement a queue in C++?

A

A linked list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fill in the blank: In a linked list implementation of a queue, each node contains data and a ________ to the next node.

A

pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two main operations of a queue?

A

Enqueue (adding an element) and Dequeue (removing an element).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the enqueue operation do?

A

It adds an element to the back of the queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the dequeue operation do?

A

It removes and returns the front element of the queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the time complexity of the enqueue operation in a linked list queue?

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the time complexity of the dequeue operation in a linked list queue?

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False: A queue can be implemented using an array.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a common issue with using arrays for queue implementation?

A

Fixed size and potential overflow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does it mean for a queue to be ‘empty’?

A

It means there are no elements in the queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can you check if a queue implemented with a linked list is empty?

A

By checking if the head pointer is null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: The front element of the queue is accessed through the ________ pointer.

A

head

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the role of the rear pointer in a linked list queue?

A

It points to the last element in the queue.

17
Q

What happens if you try to dequeue from an empty queue?

A

It can lead to an underflow condition or an error.

18
Q

True or False: A queue can grow and shrink dynamically when implemented with a linked list.

19
Q

What is the purpose of a destructor in a linked list queue implementation?

A

To free up memory by deleting all nodes when the queue is no longer in use.

20
Q

What is the significance of the ‘Node’ structure in a linked list queue?

A

It represents each element in the queue, containing data and a pointer to the next node.

21
Q

How do you implement the enqueue operation in a linked list queue?

A

Create a new node, set its next pointer to null, and link it to the current rear node.

22
Q

What should you do with the rear pointer after an enqueue operation?

A

Update the rear pointer to point to the new node.

23
Q

What is a circular queue?

A

A queue where the last position is connected back to the first position, forming a circle.

24
Q

True or False: A circular queue can help avoid the problem of wasted space in a linear queue.

25
What is the main disadvantage of using a linked list for queue implementation?
Increased memory overhead due to storing pointers.
26
What is a priority queue?
A type of queue where elements are dequeued based on priority rather than order of insertion.