Practice Flashcards
Flip to reveal answersWhat is a stack?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All 5 Flashcards — Stacks (LIFO)
Sign up free to track progress and get spaced-repetition review schedules.
Question
What is a stack?
Answer
A structure that allows adding and removing at one end only, the top. The last item put in is the first taken out — last in, first out, or LIFO.
Question
What are the four stack operations?
Answer
push adds an item on top; pop removes the top item and returns it; peek returns the top item without removing it; isEmpty says whether there is anything in the stack at all.
Question
Why are all stack operations O(1)?
Answer
Every operation touches only the top. Nothing is shifted along and nothing is searched for, so the cost is the same whether the stack holds three items or three million.
Question
Give three uses of a stack.
Answer
Undo, where the most recent action must be reversed first; the call stack, since function calls unwind in reverse order; and checking that brackets match, because the most recent opening bracket must close first.
Question
What causes a stack overflow?
Answer
A stack that keeps growing with nothing being popped until it runs out of memory — usually a function that calls itself with no way to stop.
Read the notes
Full study notes for Stacks (LIFO)
Topic 6.2 hub
Data structures
More from Topic 6.2
All flashcards in this topic
Computer Science exam skills
Paper structures & tips
Track your progress with spaced repetition
Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.
Start Free