Learning Rooms/○ Level 3 · Innovator/Computing and algorithms
Data Structures: Stacks and Queues
HackerRank · Length: see YouTube · captions on YouTube · nothing loads until you press play
By the end you can…
- Use a list as a stack (append/pop) and collections.deque as a queue (append/popleft).
- Trace the contents of a stack or queue through a sequence of operations.
- Choose last-in-first-out or first-in-first-out for an engineering task and justify it.
Watch it all: no segment has been checked by hand for this video yet.
1.Predict before you press play
A queue receives jobs 101, 102, 103, then serves one job, then receives 104. Which job is served next?
Pick one before you press play. A wrong guess is fine: it is what makes the video stick.
2.See the idea first
Play with this diagram for a minute. It gives you something to hang the video on.
Loading the interactive…
Can't use the diagram? Read a description instead
The stack and queue modes show items in a row, oldest on the left. In a stack, append adds to the right and pop removes from the right (newest). In a queue, append adds to the right and popleft removes from the left (oldest). Popping from an empty structure shows IndexError.
3.Watch, actively
Contrasts last-in-first-out with first-in-first-out using clear diagrams, the two orders behind undo and job queues.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
Watch for…
- → Watch for the two operations each structure allows and which end of the line they use.
Pause whenever you like. Rewatching a hard minute is a good habit, not a failure.
Can't stream it? Read the idea instead
A stack hands back the most recently added item first (last in, first out), like a pile of plates or an undo history. A queue hands back the oldest item first (first in, first out), like a line at a counter or jobs waiting for a printer.
What the video covers (our own note, written when we verified it): Contrasts last-in-first-out with first-in-first-out using clear diagrams, the two orders behind undo and job queues.
Written by Tactiverge in our own words, not a transcript. The full lesson below explains the idea without the video.
Read it instead
- Lesson: Stacks and queues: who goes next? · The full lesson explains the idea in text, worked examples and diagrams, with no video needed.
- Engineering Atlas: Lists, dictionaries and tabular data · A robot's test log becomes easy to analyse once each row is a record with named fields instead of a line of loose numbers.
- Field Guide: Lists and indexing · A short reference entry on the same idea.
Jot down one thing that surprised you and one question you still have.
4.Practise what you just saw
These come from the lesson that use this video and are checked on the server. Wrong answers get a hint and another try.
Practice 1
An editor's undo button should reverse the most recent change first. Which structure?
Practice 2
Why use deque.popleft() instead of list.pop(0) for a long job queue?
Practice 3 · a fresh version every time
An editor keeps an undo stack of waypoint ids: s = []; s.append(38); s.append(23); s.append(27); s.pop(); s.append(33); s.pop(); s.append(3); s.pop(). What value does the final s.pop() return?
Practice 4
What does 'while q:' do when q is an empty deque?
6.Where engineers use it
Robot task schedulers use FIFO queues for fairness; motion planners use stacks to backtrack out of dead ends; breadth-first search (next lesson) is simply 'keep the frontier in a queue'.
From the applied view in the lesson Stacks and queues: who goes next?. Checked by automated tests only.
7.Build something with it
Follow-up project
Simulate a robot cell: jobs arrive at known times and each takes a known number of minutes. Use a deque to serve them in order and record each job's waiting time. Then try a stack instead and compare the longest wait. Which is fairer, and when might the stack be acceptable?
Where this video lives
- Stacks and queues: who goes next? · Level 3, week 4
In the course catalogue: CSE-310 Structured programs and data
The video is by HackerRank, embedded from YouTube with privacy-enhanced mode and never autoplayed. The room around it (prompts, notes, practice, projects) is Tactiverge's, written with AI assistance and checked by automated tests only.