Recall & Review
beginner Click to reveal answer
What is a stack in data structures?
A stack is a collection where elements are added and removed only from the top. It follows the Last In, First Out (LIFO) principle.
beginner Click to reveal answer
Explain the LIFO principle in simple terms.
LIFO means the last item you put in is the first one you take out, like a stack of plates where you take the top plate first.
beginner Click to reveal answer
What are the two main operations of a stack?
The two main operations are push (to add an item on top) and pop (to remove the top item).
intermediate Click to reveal answer
In Rust, which data structure can be used to implement a stack easily?
A
Vec<T> (vector) can be used as a stack by using push to add and pop to remove elements from the end.beginner Click to reveal answer
Why is a stack useful in programming?
Stacks help manage tasks like undo actions, function calls, and expression evaluation because they keep track of the order in which things happen.
Which operation removes the top element from a stack?
✗ Incorrect
The pop operation removes the top element from the stack.
What does LIFO stand for?
✗ Incorrect
LIFO means Last In, First Out, describing how stacks work.
In Rust, which method adds an element to the top of a stack implemented with Vec?
✗ Incorrect
The push method adds an element to the end of a Vec, acting as the top of the stack.
If you push elements 1, 2, 3 in order, which element will pop return first?
✗ Incorrect
Because of LIFO, the last pushed element (3) is popped first.
Which real-life example best illustrates a stack?
✗ Incorrect
A stack of books where you take the top book first is a perfect example of LIFO.
Describe how a stack works and explain the LIFO principle with a simple example.
Think about how you add and remove items from a pile.
You got /3 concepts.
List the main operations of a stack and how you would implement them using Rust's Vec.
Consider how Vec methods correspond to stack actions.
You got /3 concepts.
