Stage 4 · Lesson 4 of 10
Stacks and queues
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 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
- CoursePaidGrokking Data Structures & Algorithms for Coding Interviews
Design Gurus · Beginner · Subscription
Each structure built from first principles, with solutions in Python, Java, C++, JavaScript and C#
- CourseFreeCS50: Introduction to Computer Science
Harvard University · Beginner
Free: weeks 3 and 5 cover searching, sorting, linked lists, hash tables and trees
Practise
Keep handy
Also worth your time
Time and space complexity worked through five common algorithms