1. Array
Start your learning journey by understanding the most fundamental data structure.
2. Singly Linked List
Learn in-depth the most fundamental data structure in a programmer's life
6. Queue
Learn about the data structure that powers CPU and disk scheduling algorithms
7. Binary Tree
Learn all about the most critical data structure in computer science
What you will learn
How LIFO ordering powers browser back, editor undo, and the processor's call stack
Two stack implementations: a bounded array-backed stack and an unbounded linked-list-backed stack
Infix, postfix, and prefix notation, and how to evaluate and convert between them
The monotonic stack idiom for previous and next greater or smaller element problems
Sequence validation and linear evaluation patterns for parentheses, paths, and bracketed expressions
How to design a min stack and a max stack that return their extreme value in O(1)
Why this course
push and pop are the easy half. The harder half is recognising that the next greater element, the largest rectangle in a histogram, trapped rainwater, and the stock span problem are the same monotonic-stack pattern wearing four different costumes. The clue in every one of them is the same single word: monotonic. Once you see it, the solution is six lines of code on top of a data structure you already know.
This course rebuilds your understanding of the stack from LIFO ordering up, then walks you through the five problem-solving patterns that cover almost every stack question asked in a coding interview. You finish by designing a min stack and a max stack that report their extreme value in O(1).
Requirements
The course assumes you can read code in any mainstream language and have seen an array before, but no prior stack experience is needed.
- Comfort writing loops, conditionals, and functions in at least one language.
- Familiarity with arrays and basic Big-O notation (O(1), O(N), O(N log N)).
- Optional: prior exposure to linked lists, which the second implementation chapter relies on.
Overview
A stack is the data structure your processor already uses to make function calls work. Every recursive program, every return statement, every backtracking search depends on a stack frame somewhere in memory. The same LIFO discipline that runs your call stack also collapses several otherwise quadratic problems, like next greater element and largest rectangle in histogram, into clean O(N) scans over the input.
Representation of a stack
This course covers both halves of the problem: how the data structure actually works, and how to recognise which of the five standard patterns a given problem fits into.
Fundamentals
The course opens with the LIFO insight itself. You see why browsers, text editors, and the processor's call stack all need a structure that hands back the most recent insertion first, and how restricting access to a single end turns push, pop, top, and size into O(1) operations.
From there you build the stack twice. The first implementation uses a fixed-capacity array with a topIndex field, bounded behaviour, and constant-time push and pop. The second uses a singly linked list with the head node as the top, giving you an unbounded stack at the cost of one allocation per push. Both implementations expose the same four operations, and the side-by-side comparison makes the time and space trade-offs concrete.
The fundamentals close with expression notation. You learn why infix is what humans read but a chore to evaluate, why postfix and prefix drop precedence and parentheses entirely, and how a single stack evaluates a postfix or prefix expression in O(N). The same machinery powers six conversion lessons covering every direction between the three notations.
Problem solving
After the fundamentals, the rest of the course is patterns. Most stack problems you will see in an interview reduce to one of five templates. Spot the template on first read, and the push, pop, and update rules fall out almost mechanically.
Each pattern is taught in three layers. First an Understanding lesson explains the technique on a problem where the pattern is obvious. Then an Identifying lesson teaches you the signals that tell you a new problem fits the template, the same triggers an experienced engineer spots on first read of the question. Then four to seven problems give you progressively harder applications. The course closes with a design capstone where you implement a min stack and a max stack, both returning their extreme value in O(1) by maintaining a second stack in sync with the main one.
How this course is different
Most stack material online either skips the implementation work or skips the monotonic patterns where stacks earn their reputation. This course commits to both.
Who this course is for
The course suits anyone who needs to understand the stack as a tool, not just a vocabulary word.
- New programmers who can call
stack.push(x)but cannot explain why the call stack is a stack. - Self-taught and bootcamp graduates who solved the parentheses checker once and want to see why the same template solves four other problems.
- Working developers who write recursive code daily but have never traced the call stack on paper.
- Engineers preparing for FAANG and Big Tech interviews, where next greater element, largest rectangle in histogram, and trapping rainwater are standard onsite questions.
- Returning engineers who learned postfix evaluation in school and want a refresher anchored in real interview problems.
- Anyone who has tried to solve "Largest Rectangle in Histogram" by hand and walked away unsure what the stack was tracking.
Continue your DSA journey
The stack sits at the centre of several other topics in this curriculum. After this course, the natural next steps depend on which direction you want to go.
- Array: Every problem in the previous-closest and next-closest patterns is an array problem, and the array-backed stack is the more efficient of the two implementations. The array course covers the eight patterns that stacks frequently work alongside, including the two-pointer family that the reversal pattern competes with.
- Singly linked list: The linked-list-backed stack implementation in this course assumes you can already reason about node pointers and head insertion. If that chapter felt shaky, the singly linked list course covers the underlying mechanics in depth.
- Queue: Stack and queue are the two restricted-access linear structures, LIFO and FIFO respectively. Studying them in sequence makes the difference between depth-first search (stack) and breadth-first search (queue) obvious once you reach the graph course.
- Binary tree: Iterative inorder, preorder, and postorder traversal of a binary tree all use an explicit stack to simulate the call stack that recursion uses implicitly. The binary tree course has dedicated lessons on each iterative traversal where the patterns you learned here turn into working code.
- Recursion: The call stack is itself a stack, so every recursion lesson is also a stack lesson in disguise. The recursion course teaches the call-stack frame discipline that explains why iterative tree traversal needs an explicit stack and how tail recursion can sometimes remove it.
- Backtracking: Every backtracking search uses the call stack to remember choices it can undo. Understanding the stack first makes the backtracking course's three search patterns far less mysterious, because the "undo on the way back up" step is just a pop.
Frequently asked questions
for loop and read Big-O notation. You build the stack from scratch twice before any pattern lesson begins.