Queues Flashcards

(21 cards)

1
Q

On what kind of basis is data retrieved from a queue?

A

First-In-First-Out

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

What are the key operations of a queue?

A
  • Add and item
  • Remove an item
  • Test for an empty queue
  • Test for a full queue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are queues comprised of?

A
  • Sequence of items
  • Rear pointer
  • Front pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the uses of queues?

A
  • Maintaining a queue of print jobs
  • Managing an input buffer
  • Handling multiple file downloads
  • Maintaining a playlist of media
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a linear queue?

A

A simple static and array based implementation of a queue

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

What are the advantages and disadvantages of linear queues?

A

+Simple to program
-Can lead to wasted capacity if elements at front of array are empty after dequeueing
-Process of shuffling data to solve issue of wasted capacity is inefficient

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

What is a circular queue?

A

A static array based implementation of a queue with “wrapping” front and rear pointers

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

What are the advantages and disadvantages of a circular queue?

A

+It avoids wasted space with no need of shuffling
- more complex to implement
(-Can still run out of storage space)

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

What are the different types of queues?

A
  • Linear
  • Circular
  • Priority
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you test if a linear queue is empty?

A

Check if the front pointer is greater than rear pointer

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

How do you test of a linear queue is full?

A

Check if the index indicated by rear pointer is equal to max size of queue -1

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

How do you enqueue items in a linear queue?

A
  1. Check if full
  2. Increment rear pointer
  3. Assign item to index indicated by rear pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you dequeue items in a linear queue?

A
  1. Check if empty
  2. Return value at the front pointer
  3. Increment front pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you peek a linear queue?

A
  1. Check if empty
  2. Return value at front pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you enqueue items in a circular queue?

A
  1. Check if queue is full
  2. Increment rear pointer and modulus it with the maximum size of the array
  3. Add items at index indicated by rear pointer
  4. Increment queue size
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you dequeue items from a circular queue?

A
  1. Check if empty
  2. Store removed item
  3. Increment front pointer and modulus with maximum size of the array
  4. Decrement the queue size and return item
17
Q

What area the differences between a circular and linear queue? (Structure only)

A
  • Circular more efficient but also more complex
  • Circular can wrap around memory locations
  • No space is wasted after dequeueing
  • Linear queues shuffle to avoid wasted space but this is inefficient
  • Circular queues don’t need to do this
18
Q

What is a priority queue?

A

A type of queue where each item in the queue has a priority.

19
Q

How do priority queues work?

A
  • Items are stored within the queue based on priority with highest priority at the front.
  • When enqueueing we search for an item that has less priority and insert the item in front of it by shuffling everything after it
  • This preserves FIFO within priority levels
20
Q

How do you enqueue items onto priority queue

21
Q

How do you dequeue items from priority queue