Stack
A linear structure where the last element in is the first out, like a stack of plates.
Example
You put down plates A, B and C. When taking them off, C comes first, then B and finally A.
Test yourself: Stack
Stacks
In a stack, the last element in is the ___ out.
You push A, B and C, in that order. The 1st out is C, the last one in; A, which went in 1st, comes out 3rd.
Stacks
You push 1, 2 and 3 and pop twice. What's left in the stack is ___.
3 and 2 come out, in that order. Only 1 is left, the first one in.
Stacks
In an array-based stack, why does the top go at the end and not the start?
With the top at the start, each push would shift everything: with 10,000 elements, 10,000 moves per operation.
0/3
â–¶ PlayLessons that use it
Iteration and recursion
2 ways to repeat
Time complexity
Count steps, not seconds
Space complexity
How much memory it asks for
Types of structures
How they relate and where they live
Arrays
Adjacent cells
Linked lists
Links of a chain
Memory and cache
Close is fast
Stacks
Last in, first out
Queues
First in, first out
Deques
In and out at both ends
Walking a tree
By levels or by branches
Graphs
Points and connections
Walking a graph
BFS and DFS, now with cycles
Quick sort
A pivot and 2 sides
Merge sort
Split in half and merge in order
Tower of Hanoi
n − 1, 1 and n − 1
Subset sum
Groups that add up exactly
Dynamic programming
Solve each thing only once
Maximum product cutting
Cut into threes
Databases
Where data is kept
