Queues Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What type of data structure is a queue?

A

It’s a FIFO data structure

First in First out

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

What are some real life examples of a queue being used?

A
  • Characters typed into a keyboard are held in a queue in a keyboard buffer
  • Output waiting to be printed is stored in a queue on disk. The output is then printed on a first served basis when the printer is free.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How many pointers does a queue data structure have?

A

It has 2 pointers, the front and the rear

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

What happens in the queue data structure when items are added/removed?

A

The front pointer moves. None of the elements move.

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

What are the 4 operations that can be carried out on a queue?

A
  • enQueue(item)
  • deQueue()
  • IsEmpty()
  • isFull()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the enQueue(item) operation do?

A

Adds a new item to the rear of the queue

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

What does the deQueue() operation do?

A

Removes the first item from the front of the queue and returns it

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

What does the isEmpty() operation do?

A

Tests to see whether the queue is empty

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

What does the isFull() operation do?

A

Tests to see whether the queue is full

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

What is the heap?

A

A portion of memory from which space is automatically allocated and de-allocated as required

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

What is a static data structure?

A

Where the size of the data structure is fixed once it is defined. For example an array

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

What is a dynamic data structure?

A

Where the size of the data structure can grow or shrink

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

Why are dynamic data structures useful?

A

They are useful for implementing data structures (queues) where the size of the data structure is not known in advance

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

What is an advantage of using a static data structure?

A

No pointers or excess information about the data structure needs to be stored

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

What is a disadvantage of using a static data structure?

A

Memory that has been allocated to the data structure cannot be reallocated even if most of it is unused

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

What is one way to implement a linear queue in an array or list.

A

As items are removed, all the other items move up one space so the front of the queue is always the first element of the data structure

17
Q

How does a circular queue solve the limitations of a implementing a linear queue?

A

When the array fills up and the rear pointer points to the last element in the array (assuming it is empty) the rear pointer will be made to point to the first element in the array when another item is enqueued.

18
Q

How does a priority queue act?

A

It continues to act as a FIFO data structure, however items with a high priority can be added to the front of the queue instead of the rear.

19
Q

How could a priority queue be implemented?

A
  • By checking the priority of each item in the queue
  • starting at the front and moving along one item until an item with the same/lower priority if found
  • At which point the item can be inserted