Preview

04 - Queues Algorithms

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

  LIRO

  FIRO

  FIFO

  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 __________________

  Dequeue

  Insertion

  FIFOing

  Deletion

 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.

  Just 2

  1 and 3

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

  Just 1

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

  single variable

  linked list

  pointer

  enqueue list

 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 _____

  Answer:0

  Answer: -1

  Answer:NULL

  Answer: 1

 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()

  ERROR

  dog

  2

  2,dog

 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
while (not found and queue is not empty)
4. #WHAT HAPPENS HERE?
5. Find all possible choices after the last one tried
6. Enqueue these choices onto the queue
7. Return

  Enqueue the queue

  Dequeue the queue

  Create a new 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 more than one variable

  waste of space

  use of a pointer

  use of a stack