Question 41
MediumTwo stacks implement a queue. What is the amortised cost of dequeue?
- 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
Two stacks implement a queue. What is the amortised cost of dequeue?
O(1)
O(n²)
O(n)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
Which queue variant allows insertion and deletion at both ends?
Deque
Priority queue
Circular queue
Simple queue
Sign up free to see the answer and a step-by-step explanation.
What does an operating system's ready queue under round-robin scheduling behave like?
A stack
A max-heap
A hash table
A circular FIFO queue
Sign up free to see the answer and a step-by-step explanation.
Which traversal of a binary tree uses a queue?
Postorder traversal
Preorder traversal
Level-order traversal
Inorder traversal
Sign up free to see the answer and a step-by-step explanation.
A printer queue receives jobs A, B, C. B is cancelled. Which data structure makes cancelling from the middle easy?
A heap
An array queue with no shifting
A doubly linked list based queue
A stack
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of insertion and removal of the highest-priority item in a binary-heap priority queue?
O(n log n) each
O(log n) each
O(n) each
O(1) each
Sign up free to see the answer and a step-by-step explanation.
Why does BFS on an unweighted graph find shortest paths?
The queue processes vertices in order of distance from the source
It visits vertices randomly
It sorts the edges
It uses a stack
Sign up free to see the answer and a step-by-step explanation.
What is a blocking queue used for in concurrent programs?
Producer–consumer coordination: take() waits when empty and put() waits when full
Sorting data
Storing passwords
Caching web pages
Sign up free to see the answer and a step-by-step explanation.
In an array queue without wrap-around, why does space get wasted?
The array shrinks
Elements are stored twice
It can't be wasted
The front moves forward on each dequeue, and the freed slots at the start are never reused
Sign up free to see the answer and a step-by-step explanation.
Which structure can generate binary numbers 1 to n in order (1, 10, 11, 100 …)?
A queue: dequeue s, output it, enqueue s + '0' and s + '1'
A min-heap of integers
A hash set
A stack
Sign up free to see the answer and a step-by-step explanation.