Concept
A stack is last in, first out. It fits anything that nests or must be undone in reverse: matching brackets, evaluating expressions, backtracking, and the call stack itself.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Stack applications doing its job.
def balanced(text):
pairs = {")": "(", "]": "[", "}": "{"}
stack = []
for ch in text:
if ch in "([{":
stack.append(ch)
elif ch in pairs:
if not stack or stack.pop() != pairs[ch]:
return False
return not stack
balanced("{[()]}") # TrueReturning True as soon as the loop finishes. Unclosed openers are still on the stack, so "((" would pass; the stack must be empty at the end.
Your roadmap puts these before Stack applications, unless you already know them.
Once a session shows you understand Stack applications, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Stack applications.