Question 21
EasyStarting with an empty queue, you enqueue 10, 20 and 30 and then dequeue twice. How many elements remain?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
Starting with an empty queue, you enqueue 10, 20 and 30 and then dequeue twice. How many elements remain?
2
1
0
3
Sign up free to see the answer and a step-by-step explanation.
What does the peek (front) operation of a queue do?
Returns the front element without removing it
Adds an element
Empties the queue
Removes the rear element
Sign up free to see the answer and a step-by-step explanation.
Characters typed on a keyboard are held until the program reads them, in the order typed. Which structure is this?
A graph
A queue (buffer)
A stack
A tree
Sign up free to see the answer and a step-by-step explanation.
What is another name for a double-ended queue?
Stack
Deque
Trie
Heap
Sign up free to see the answer and a step-by-step explanation.
In a producer–consumer system, what does a blocking queue do when it is empty?
Returns a random item
Makes the consumer wait until an item is added
Deletes itself
Crashes the program
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of enqueue in a queue built on a circular array that is not full?
O(n²)
O(log n)
O(n)
O(1)
Sign up free to see the answer and a step-by-step explanation.
Which extra structure lets you reverse the order of the elements in a queue?
Another queue only
A hash map
A stack
A binary search tree
Sign up free to see the answer and a step-by-step explanation.
What problem does a circular queue solve in an array implementation?
Making the queue sorted
Reusing the empty space at the front after elements are dequeued
Allowing random access
Removing the need for a size limit
Sign up free to see the answer and a step-by-step explanation.
In a circular queue of size 5 (array indices 0–4), rear is at index 4. Where is the next element inserted if index 0 is free?
Index 0
It overflows
Index 4
Index 5
Sign up free to see the answer and a step-by-step explanation.
What is a priority queue?
A queue sorted by arrival time
A queue that never removes
A queue where the element with the highest priority is removed first
A stack with priorities
Sign up free to see the answer and a step-by-step explanation.