[go: up one dir, main page]

0% found this document useful (0 votes)
338 views5 pages

QUEUE

1. A queue is a linear data structure where elements are inserted at the rear end and deleted at the front end, following FIFO (First In First Out) order. 2. Breadth-first traversal of a graph uses a queue data structure because it needs to follow FIFO order by processing the adjacent unvisited vertices of the starting vertex first before moving deeper into the graph. 3. Circular queues, also known as ring buffers, are queues that connect the rear and front positions to form a circle so that the queue space is used efficiently without waste.

Uploaded by

MohammadMoiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
338 views5 pages

QUEUE

1. A queue is a linear data structure where elements are inserted at the rear end and deleted at the front end, following FIFO (First In First Out) order. 2. Breadth-first traversal of a graph uses a queue data structure because it needs to follow FIFO order by processing the adjacent unvisited vertices of the starting vertex first before moving deeper into the graph. 3. Circular queues, also known as ring buffers, are queues that connect the rear and front positions to form a circle so that the queue space is used efficiently without waste.

Uploaded by

MohammadMoiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the
other end (rear) is known as _____________

a) Queue

b) Stack

c) Tree

d) Linked list

Answer: a

Explanation: Linear list of elements in which deletion is done at front side and insertion at rear side is called Queue. In
stack we will delete the last entered element first.

2. The data structure required for Breadth First Traversal on a graph is?

a) Stack

b) Array

c) Queue

d) Tree

Answer: c

Explanation: In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent vertices which are
unvisited are also taken. Again, the first vertex which was added as an unvisited adjacent vertex list will be considered to
add further unvisited vertices of the graph. To get the first unvisited vertex we need to follows First In First Out principle.
Queue uses FIFO principle.

3. A queue follows __________

a) FIFO (First In First Out) principle

b) LIFO (Last In First Out) principle

c) Ordered array

d) Linear tree

Answer: a

Explanation: Element first added in queue will be deleted first which is FIFO principle.
4. Circular Queue is also known as ________

a) Ring Buffer

b) Square Buffer

c) Rectangle Buffer

d) Curve Buffer

Answer: a

Explanation: Circular Queue is also called as Ring Buffer. Circular Queue is a linear data structure in which last position
is connected back to the first position to make a circle. It forms a ring structure.

5. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order will they be
removed?

a) ABCD

b) DCBA

c) DCAB

d) ABDC

Answer: a

Explanation: Queue follows FIFO approach. i.e. First in First Out Approach. So, the order of removal elements are
ABCD.

6. A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?

a) Queue

b) Circular queue

c) Dequeue

d) Priority queue

Answer: c

Explanation: In dequeuer, we can insert or delete elements from both the ends. In queue, we will follow first in first out
principle for insertion and deletion of elements. Element with least priority will be deleted in a priority queue

7. A normal queue, if implemented using an array of size MAX_SIZE, gets full when?

a) Rear = MAX_SIZE – 1

b) Front = (rear + 1)mod MAX_SIZE

c) Front = rear + 1

d) Rear = front

Answer: a

Explanation: When Rear = MAX_SIZE – 1, there will be no space left for the elements to be added in queue. Thus queue
becomes full.
8. Queues serve major role in ______________

a) Simulation of recursion

b) Simulation of arbitrary linked list

c) Simulation of limited resource allocation

d) Simulation of heap sort

Answer: c

Explanation: Simulation of recursion uses stack data structure. Simulation of arbitrary linked lists uses linked lists.
Simulation of resource allocation uses queue as first entered data needs to be given first priority during resource
allocation. Simulation of heap sort uses heap data structure.

9. Which of the following is not the type of queue?

a) Ordinary queue

b) Single ended queue

c) Circular queue

d) Priority queue

Answer: b

Explanation: Queue always has two ends. So, single ended queue is not the type of queue.

10. Which of the following is not a disadvantage to the usage of array?


a) Fixed size
b) There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size
c) Insertion based on position
d) Accessing elements at specified positions

Answer: d
Explanation: Array elements can be accessed in two steps. First, multiply the size of the data type with the specified
position, second, add this value to the base address. Both of these operations can be done in constant time, hence
accessing elements at a given index/position is faster

11. Which of the following data structures can be used for parentheses matching?
a) n-ary tree
b) queue
c) priority queue
d) stack

Answer: d
Explanation: For every opening brace, push it into the stack, and for every closing brace, pop it off the stack. Do not
take action for any other character. In the end, if the stack is empty, then the input has balanced parentheses.

12. Minimum number of queues to implement stack is ___________


a) 3
b) 4
c) 1
d) 2

Answer: c
Explanation: Use one queue and one counter to count the number of elements in the queue.
13. Which of the following properties is associated with a queue?
a) First In Last Out
b) First In First Out
c) Last In First Out
d) Last In Last Out

Answer: b
Explanation: Queue follows First In First Out structure.

14. In a circular queue, how do you increment the rear end of the queue?
a) rear++
b) (rear+1) % CAPACITY
c) (rear % CAPACITY)+1
d) rear–
Answer: b
Explanation: Ensures rear takes the values from 0 to (CAPACITY-1).

15. What is the term for inserting into a full queue known as?
a) overflow
b) underflow
c) null pointer exception
d) program won’t be compiled

Answer: a
Explanation: Just as stack, inserting into a full queue is termed overflow.

16. What is the time complexity of enqueue operation?


a) O(logn)
b) O(nlogn)
c) O(n)
d) O(1)

Answer: d
Explanation: Enqueue operation is at the rear end, it takes O(1) time to insert a new item into the queue.

17. What is the need for a circular queue?


a) effective usage of memory
b) easier computations
c) to delete elements based on priority
d) implement LIFO principle in queues

Answer: a
Explanation: In a linear queue, dequeue operation causes the starting elements of the array to be empty, and there is
no way you can use that space, while in a circular queue, you can effectively use that space. Priority queue is used to
delete the elements based on their priority. Higher priority elements will be deleted first whereas lower priority
elements will be deleted next. Queue data structure always follows FIFO principle.

18. With what data structure can a priority queue be implemented?


a) Array
b) List
c) Heap
d) Tree
Answer: d
Explanation: Priority queue can be implemented using an array, a list, a binary search tree or a heap, although the
most efficient one being the heap.

19. Which of the following is not an application of priority queue?


a) Huffman codes
b) Interrupt handling in operating system
c) Undo operation in text editors
d) Bayesian spam filter
Answer: c
Explanation: Undo operation is achieved using a stack.

20. What is not a disadvantage of priority scheduling in operating systems?


a) A low priority process might have to wait indefinitely for the CPU
b) If the system crashes, the low priority systems may be lost permanently
c) Interrupt handling
d) Indefinite blocking
Answer: c
Explanation: The lower priority process should wait until the CPU completes the processing higher priority process.
Interrupt handling is an advantage as interrupts should be given more priority than tasks at hand so that interrupt can
be serviced to produce desired results.

21. Which of the following is not an advantage of a priority queue?


a) Easy to implement
b) Processes with different priority can be efficiently handled
c) Applications with differing requirements
d) Easy to delete elements in any case
Answer: d
Explanation: In worst case, the entire queue has to be searched for the element having the highest priority. This will
take more time than usual. So deletion of elements is not an advantage.

22. What is a dequeue?


a) A queue with insert/delete defined for both front and rear ends of the queue
b) A queue implemented with a doubly linked list
c) A queue implemented with both singly and doubly linked lists
d) A queue with insert/delete defined for front side of the queue
Answer: a
Explanation: A dequeue or a double ended queue is a queue with insert/delete defined for both front and rear ends of
the queue.

23. If the MAX_SIZE is the size of the array used in the implementation of circular queue. How is rear
manipulated while inserting an element in the queue?

a) rear=(rear%1)+MAX_SIZE
b) rear=rear%(MAX_SIZE+1)
c) rear=(rear+1)%MAX_SIZE
d) rear=rear+(1%MAX_SIZE)

ANSWER: c) rear=(rear+1)%MAX_SIZE

24. A circular queue is implemented using an array of size 10. The array index starts with 0, front is 6, and rear
is 9. The insertion of next element takes place at the array index.

a) 0
b) 7
c) 9
d) 10
ANSWER: a) 0

You might also like