Programming foundations

Stage 4 · Lesson 4 of 10

Stacks and queues

Data structures and Big-O

A is last in, first out (LIFO): you push and pop at the same end, like a pile of plates. It is how calls work, and how you undo actions or match brackets. A is first in, first out (FIFO): you add at the back and remove from the front, like a line at a shop.

Queues hold tasks waiting their turn, and later you will use one for . Both should do every operation in O(1). Use a proper type, such as Python's collections.deque, Java's ArrayDeque, C++'s std::queue or C#'s Queue<T>, or a head index in JavaScript, and build both once yourself.

Common trapa queue built on a plain list that removes from the front, which is O(n).

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Practise

Keep handy

  • Step through linked lists, hash tables and sorts with your own input

  • Chapter 5 on lists, dicts, sets and deque: the built-ins you will use from now on

Also worth your time

Mark this stage as not done?