Recall & Review
beginner
What is the main difference between a stack and a queue?
A stack follows Last In First Out (LIFO) order, meaning the last item added is the first to be removed. A queue follows First In First Out (FIFO) order, meaning the first item added is the first to be removed.
Click to reveal answer
beginner
When should you use a stack?
Use a stack when you need to reverse things, track history, or handle nested structures. Examples include undo features, parsing expressions, and backtracking algorithms.
Click to reveal answer
beginner
When is a queue the better choice?
Use a queue when you want to process items in the order they arrive, like in task scheduling, breadth-first search, or handling requests in order.
Click to reveal answer
intermediate
How does a stack help in function calls?
A stack keeps track of active function calls, storing return addresses and local variables. This helps the program return to the right place after a function finishes.
Click to reveal answer
intermediate
Why is a queue useful in breadth-first search (BFS)?
A queue processes nodes in the order they are discovered, ensuring BFS explores all neighbors at the current depth before moving deeper, which is essential for correct traversal.
Click to reveal answer
Which data structure would you use to implement an undo feature?
✗ Incorrect
Undo features require reversing actions, which fits the Last In First Out (LIFO) behavior of a stack.
Which data structure processes elements in the order they arrive?
✗ Incorrect
A queue follows First In First Out (FIFO), so it processes elements in arrival order.
What order does a stack follow?
✗ Incorrect
Stack follows Last In First Out (LIFO) order.
Which data structure is best for breadth-first search (BFS)?
✗ Incorrect
BFS uses a queue to explore nodes level by level.
If you want to track nested tasks, which data structure is most suitable?
✗ Incorrect
Stacks are ideal for nested tasks because they handle last started tasks first.
Explain when you would choose a stack over a queue and give two real-life examples.
Think about situations where the last thing you did needs to be undone or finished first.
You got /4 concepts.
Describe why a queue is preferred for task scheduling and breadth-first search.
Consider how tasks or nodes should be handled in the order they arrive.
You got /4 concepts.
