Queues Flashcards

1
Q

What is an Abstract Data Type (ADT)?

A

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.

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

What is a queue?

A

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.

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

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

A

False

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

What are the primary operations of a queue?

A

The primary operations of a queue are enqueue (adding an element), dequeue (removing an element), and peek (viewing the front element without removing it).

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

Fill in the blank: In a queue, elements are added at the _____ and removed from the _____.

A

rear; front

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

What is the main difference between a queue and a stack?

A

A queue follows the FIFO principle, while a stack follows the Last-In-First-Out (LIFO) principle.

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

What is a circular queue?

A

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.

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

True or False: A circular queue can lead to wasted space if not implemented correctly.

A

True

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

What is a priority queue?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does a priority queue differ from a regular queue?

A

In a priority queue, elements are removed based on priority, whereas in a regular queue, elements are removed in the order they were added.

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

What data structure is commonly used to implement a priority queue?

A

A binary heap is commonly used to implement a priority queue.

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

Fill in the blank: The operation to remove an element from a queue is called _____

A

dequeue

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

What is the initial condition of an empty queue?

A

The queue is said to be empty when there are no elements present in it.

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

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

A

It typically results in an underflow error, indicating that there are no elements to remove.

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

What is the purpose of the peek operation in a queue?

A

The peek operation allows you to view the front element of the queue without removing it.

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

True or False: A queue can be implemented using arrays.

A

True

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

What is the main disadvantage of using an array to implement a queue?

A

The main disadvantage is that it can lead to wasted space if elements are removed from the front and the array size is fixed.

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

What is a dequeue?

A

A dequeue (double-ended queue) is a data structure that allows insertion and deletion of elements from both the front and rear ends.

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

How do you determine if a queue is full?

A

In a fixed-size array implementation, a queue is full when the number of elements equals the maximum capacity of the array.

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

What is a blocking queue?

A

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.

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

True or False: Queues can only store homogeneous data types.

A

False

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

What is the significance of the ‘front’ pointer in a queue implementation?

A

The ‘front’ pointer tracks the first element in the queue for efficient access during dequeue operations.

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

Fill in the blank: A queue is often used in _____ algorithms for managing tasks.

A

scheduling

24
Q

What is the common application of a queue in computer science?

A

Queues are commonly used in scenarios like print job management, task scheduling, and breadth-first search algorithms.

25
What is the main advantage of using a linked list to implement a queue?
The main advantage is dynamic sizing, allowing the queue to grow and shrink as needed without wasting space.
26
What is the main drawback of using a linked list for a queue?
The main drawback is the overhead of additional memory for storing pointers.
27
What does FIFO stand for?
FIFO stands for First-In-First-Out.
28
In which scenarios would you prefer a priority queue over a regular queue?
You would prefer a priority queue in scenarios where tasks need to be processed based on their importance rather than their arrival order.
29
What is a queue in data structures?
A queue is a linear data structure that follows the First In First Out (FIFO) principle.
30
Which operator is commonly used to add an element to a queue?
The enqueue operator is used to add an element to a queue.
31
True or False: The dequeue operator removes the last element from a queue.
False: The dequeue operator removes the first element from a queue.
32
Fill in the blank: The _____ operator is used to retrieve the front element of a queue without removing it.
peek
33
What does the term 'FIFO' stand for in queue operations?
First In First Out
34
In a queue, what happens when the enqueue operation is performed on a full queue?
It results in an overflow condition.
35
What is the purpose of the dequeue operation?
To remove and return the front element of the queue.
36
Which operator checks if a queue is empty?
The isEmpty operator checks if a queue is empty.
37
True or False: A circular queue is a variation of a regular queue that overcomes the limitation of fixed size.
True
38
Fill in the blank: A queue can be implemented using an _____ or a linked list.
array
39
Which operator is used to remove an element from the rear of a queue in a deque?
pop_back
40
What is a priority queue?
A priority queue is a data structure where each element has a priority, and elements are dequeued based on their priority rather than their order in the queue.
41
True or False: In a priority queue, the element with the highest priority is dequeued first.
True
42
What is the main difference between a queue and a stack?
A queue follows FIFO, while a stack follows Last In First Out (LIFO).
43
Fill in the blank: In a queue, the _____ operation retrieves the element at the front without removing it.
peek
44
Which operator would you use to clear all elements from a queue?
The clear operator is used to remove all elements from a queue.
45
What is the main use case for a queue in programming?
Queues are commonly used in scenarios like task scheduling, breadth-first search, and handling requests in a server.
46
True or False: A queue can only store elements of the same data type.
False: A queue can store mixed data types depending on the implementation.
47
What does the enqueue operation return upon success?
Typically, it returns a confirmation or success status.
48
What happens during a dequeue operation if the queue is empty?
It results in an underflow condition.
49
Fill in the blank: In a circular queue, the rear pointer wraps around to the _____ when it reaches the end of the array.
front
50
Which operator indicates the current size of a queue?
The size operator returns the current number of elements in the queue.
51
What is the primary advantage of a circular queue over a linear queue?
It efficiently utilizes space by reusing empty slots.
52
Fill in the blank: In a queue, elements are added at the _____ and removed from the _____ end.
rear; front
53
What type of queue allows insertion and deletion from both ends?
Deque (Double-ended queue)
54
True or False: A queue can be implemented using a linked list.
True
55
What is the primary disadvantage of using an array-based queue?
Fixed size leading to overflow if maximum capacity is reached.
56
Fill in the blank: The _____ operation is used to check the element at the end of the queue.
back