04 - Queues Algorithms

1. The queue is a ______data structure, which means that element inserted first will be removed first

FIRO

FIFO

LIRO

LIFO

2. The process to add an element into queue is called Enqueue and the process of removal of an element from queue is called __________________

FIFOing

Deletion

Dequeue

Insertion

3. Which of the following are valid applications of queues?
```1 - Serving requests on a single shared resource, like a printer, CPU task scheduling etc.

2 - In real life scenario, Call Center phone systems uses Queues to hold people calling
them in an order, until a service representative is free.

3- Handling of interrupts in real-time systems. The interrupts are handled in the same
order as they arrive i.e First come first served.```

1 and 3

Just 1

Just 2

All of the items 1,2,3 are valid applications of queues

4. A queue can be implemented using an array, stack or ________________

pointer

enqueue list

single variable

5. Two pointers called FRONT and REAR are used to keep track of the first and last elements in the queue. When initializing the queue, we set the value of FRONT and REAR to _____

6. The following shows a class implementation of a queue. What is the output of the following commands after the existing code? >>print(q.size()) and >> print(q.dequeue())
```class Queue:
def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []

def enqueue(self, item):
self.items.insert(0,item)

def dequeue(self):
return self.items.pop()

def size(self):
return len(self.items)

q = Queue()
q.enqueue('hello')
q.enqueue('dog')
q.enqueue(3)
q.dequeue()```

dog

ERROR

2,dog

2

7. In the following algorithm for a depth first search using a queue, what happens in step 4?
```In breadth-first search we explore all the nearest possibilities by finding all possible
successors and enqueue them to a queue.

1. Create a queue
2. Create a new choice point
3. Enqueue the choice point onto the queue
4. #WHAT HAPPENS HERE?
5. Find all possible choices after the last one tried
6. Enqueue these choices onto the queue
7. Return```

Create a new queue

Dequeue the queue

Enqueue the queue

Enqueue the choice point on to a new queue

8. Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the ____________________

last position is connected back to the first position to make a circle

element in the first position is deleted and replaced with the element in the second position

9. A deque, also known as a double-ended queue, is an ordered collection of items similar to the queue. It has two ends, a front and a rear, and the items remain positioned in the collection

FALSE

TRUE

10. Circular queue avoids the ________________________________in a regular queue implementation using arrays.

use of a pointer

waste of space

use of more than one variable

use of a stack