Queue Flashcards

1
Q

what is the order of operations in a queue?

A

FIFO

First in First Out

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

is the queue a concrete class or an ADT

A

it’s both as an ADT is merely that the class implements a specific behavior to be a queue

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

what are other types of queues?

A

Deque :
double ended queue meaning u can remove or add at the end of beginning of a queue which operates like a stack
Priority Queue:
u add the element to the queue according to it’s priority

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

what are the operations of a queue?

A

Enqueue
Dequeue
Empty
all of them are O(1) but with an array dequeue is O(N)

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

how to implement a queue?

A

with a linked list or an array

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

what is a circular queue?

A

it’s a data structure that uses a single, fixed size buffer as if it were connected from end to end and is used in buffering data streams

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

Uses of a circular queue or Deque

A

it’s useful because the property doesn’t need to be shuffled around when consumed and it makes good strategy when it’s of a fixed size and one of the problems that it solves is the producer-consumer-problem as it operates that the producer overwrites old data that the consumer couldn’t keep up with getting

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

when do u put the first element in a circular queue?

A

u can put it in any index

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

what happens when u write on a circular queue when it’s full?

A

it depends but in most cases it overwrites the oldest data present but u could also raise an exception

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

how to know that a circular queue is empty or full?

A

if the start pointer is equal to the end pointer then it’s empty and if the end pointer is one less than the first pointer then it’s full

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

what is the producer-consumer problem?

A

it’s when a producer puts data in a buffer and a consumer takes from that buffer taking into account that the producer wouldn’t put into a full queue and the consumer wouldn’t take from an empty queue

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

what are some solutions to producer-consumer problem

A

https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem

wake and sleep which produce a deadlock
semaphores
monitors

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