Practice question · Select all that apply
Select every statement the lesson supports about stacks and queues.
Hints
- Four statements come straight from the lesson; one describes a different ADT entirely.
- Ask what a queue uses to decide who is served next: importance, or arrival time?
Show the answer
- A. When well implemented, push, pop, enqueue and dequeue are all O(1)
- B. A deque generalises both a stack and a queue
- D. peek returns the top of a stack without removing it
- E. Both are ADTs and can be built on an array or on a linked list
Why
Stacks and queues are interfaces with constant-time operations under either implementation, peek looks without removing, and a deque relaxes both restrictions. Serving by priority is the priority queue, a different ADT, expecting a queue to know about importance is a common and expensive mix-up.
Practise Stacks and Queues
The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Stacks and Queues
- A stack starts empty and these operations run in order: push 1, push 2, pop, push 3, push 4, pop, pop, pop.…
- Both a stack and a queue store items and hand them back one at a time. Why does reversing which end you…
- Depth-first search can be written recursively with no visible stack, or iteratively with an explicit one.…