Queues Flashcards

quintessentially british

1
Q

What is a queue an example of?

A

An ordered list

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

What are the ordering criteria for the elements within a queue?

A

Time of Arrival (First in - First Out / FIFO)

Priority of the associated event / data

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

What are the items of interest in a FIFO queue?

A

First Item ( head / front)

Last Item ( tail / back)

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

enQueue

A

adds an element to the queue

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

Serve

A

returns the ‘first’ item from the queue and removes it from the queue

only way to remove data from a queue

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

getHead

A

returns the first element, leaving the queue unchanged

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

queueLength

A

the current number of data items in the data structure

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

isFull

A

returns try if the queue buffer is full

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

isEmpty

A

returns true if there are no elements in the queue

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

How can underflow occur in queues?

A

trying to “serve” an empty queue

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

How can overflow occur in queues?

A

trying to “enQueue” data into a full queue

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

How would we catch the underflow and over flow exceptions?

A

Use our own exceptions

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

An array based queue implementation can be simple if

A

adding an array to the queue involves incrementing the tail

removing an element involves incrementing the head variable

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

What is Cyclic Buffering?

A

stores data in a fixed-size buffer that is connected end-to-end

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

What does the Remainder / Modulus Operator do regarding Cyclic Buffering?

A

ensures that the indices of the buffer wrap around when they reach the end of the array

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

Using the % operator, how is a new array index value given each time an index is incremented

A

head++% or ++tail%

17
Q

What is this code showing?
import java.lang.RuntimeException;

class QueueBoundaryException extends RuntimeExeception {
QueueBoundaryException (String message){
super(message);
} // end consturctor
} // end class

A

catches exceptions in any application / program encounters them when using the queue

18
Q

What is this code showing?
public int serve() {
if (isEmpty())
throw new QueueNoundaryException (“ArrayQueue underflow”);
else {
int x = queueArray[head++];
return x;
} //end else
} // end serve

A

remove the data item currently at the head of the queue

19
Q

What is this code showing?
public class ArrayQueue implements IntQueue{
int buffer[ ];
int head, tail, count;

//constructor
public ArrayQueue (int maxqueuesize) {
	buffer = new int [maxqueuesize];
	head = 0;
	tail = -1;
	count = 0;
} // end constructor
A

Array Based Implementation for a Queue

20
Q

What is the added complexity associated with Priority Queues?

A

enQueue must ensure that the queue is maintained in priority order, meaning that the highest priority item should be at the head of the queue

21
Q

What is a limitation of arrays regarding insertion / deletion ?

A

To delete or, change the elements of an array you need to traverse throughout the array which increases the time complexity