A stack is a collection where elements are added and removed only from the top, following the Last In, First Out (LIFO) principle.
Click to reveal answer
beginner
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.
Click to reveal answer
beginner
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).
Click to reveal answer
intermediate
What happens if you try to Pop from an empty stack?
It causes an error or exception because there is no item to remove.
Click to reveal answer
intermediate
How does a stack differ from a queue?
A stack uses LIFO (last in, first out), while a queue uses FIFO (first in, first out).
Click to reveal answer
Which operation adds an element to the top of a stack?
APop
BPush
CPeek
DEnqueue
✗ Incorrect
Push adds an element to the top of the stack.
What does LIFO stand for?
ALast In, First Out
BLast In, Final Out
CList In, First Out
DLast Input, First Output
✗ Incorrect
LIFO means Last In, First Out.
If you push 1, then 2, then 3 onto a stack, which element will be popped first?
A3
B2
C1
DNone
✗ Incorrect
3 is the last pushed, so it is popped first.
Which of these is NOT a typical stack operation?
APush
BPop
CPeek
DDequeue
✗ Incorrect
Dequeue is a queue operation, not a stack operation.
What will happen if you pop from an empty stack?
ADoes nothing
BReturns the last element
CReturns null or error
DAdds a new element
✗ Incorrect
Popping from an empty stack causes an error or returns null.
Describe how a stack works using a real-life example.
Think about how you add and remove plates from a pile.
You got /3 concepts.
Explain the difference between a stack and a queue.
Compare how people line up in a queue versus how plates are stacked.
You got /3 concepts.
Practice
(1/5)
1. What does the LIFO principle mean in the context of a stack?
easy
A. Last In, First Out - the first element added is the first to be removed
B. First In, First Out - the first element added is the first to be removed
C. Last In, First Out - the last element added is the first to be removed
D. First In, Last Out - the first element added is the last to be removed
Solution
Step 1: Understand LIFO meaning
LIFO means the last item you put in is the first one you take out.
Step 2: Apply to stack behavior
Stacks follow LIFO, so the last pushed element is popped first.
Final Answer:
Last In, First Out - the last element added is the first to be removed -> Option C
Quick Check:
LIFO = Last In, First Out [OK]
Hint: Remember stack is like a stack of plates, last added removed first [OK]
Common Mistakes:
Confusing LIFO with FIFO
Thinking first added is removed first
Mixing up the order of insertion and removal
2. Which of the following is the correct way to push an integer 10 onto a stack named myStack in C#?
easy
A. myStack.Enqueue(10);
B. myStack.Push(10);
C. myStack.Insert(10);
D. myStack.Add(10);
Solution
Step 1: Recall stack push method
In C#, the method to add an element to a stack is Push.
Step 2: Check method names
Add and Insert are not stack methods; Enqueue is for queues.
Final Answer:
myStack.Push(10); -> Option B
Quick Check:
Push() adds element to stack [OK]
Hint: Use Push() to add elements to stack in C# [OK]
Common Mistakes:
Using Add() or Insert() which are not stack methods
Confusing stack with queue methods like Enqueue()
Forgetting parentheses in method call
3. What will be the output of the following C# code?
Stack<int> stack = new Stack<int>();
stack.Push(5);
stack.Push(10);
stack.Push(15);
Console.WriteLine(stack.Pop());
Console.WriteLine(stack.Peek());
medium
A. 15
10
B. 5
10
C. 10
15
D. 15
15
Solution
Step 1: Trace Push operations
Elements pushed in order: 5 (bottom), 10, 15 (top).
Step 2: Trace Pop and Peek
Pop removes and returns 15 (top). Peek returns new top 10 without removing.
Final Answer:
15\n10 -> Option A
Quick Check:
Pop() = 15, Peek() = 10 [OK]
Hint: Pop returns top and removes it; Peek returns top without removing [OK]
Common Mistakes:
Mixing Pop and Peek outputs
Assuming Pop does not remove element
Confusing order of pushed elements
4. Identify the error in the following C# code snippet using a stack:
Stack<string> stack = new Stack<string>();
stack.Push("apple");
stack.Push("banana");
string fruit = stack.Pop();
string topFruit = stack.Top();
medium
A. Stack must be initialized with capacity
B. Pop() cannot be assigned to a string variable
C. Push() method requires two arguments
D. Stack does not have a method named Top()
Solution
Step 1: Check stack methods
Stack in C# has Peek() to view top element, not Top().
Step 2: Validate other statements
Pop() returns string, Push() takes one argument, no capacity needed.
Final Answer:
Stack does not have a method named Top() -> Option D
Quick Check:
Use Peek() to view top element [OK]
Hint: Use Peek() to see top element, not Top() [OK]
Common Mistakes:
Using Top() instead of Peek()
Thinking Pop() returns void
Assuming Push() needs capacity argument
5. Given a stack with elements pushed in this order: 1, 2, 3, 4, 5. You pop two elements, then push 6 and 7. What is the order of elements if you pop all remaining elements one by one?
hard
A. 7, 6, 3, 2, 1
B. 3, 2, 6, 7
C. 5, 4, 6, 7
D. 7, 6, 3, 2
Solution
Step 1: Track initial pushes
Stack after pushes: bottom 1,2,3,4,5 top.
Step 2: Pop two elements
Pop removes 5 then 4; stack now 1,2,3 (bottom to top).
Step 3: Push 6 and 7
Stack now: 1,2,3,6,7 (bottom to top).
Step 4: Pop all remaining elements
Pop order (first popped to last): 7,6,3,2,1.
Final Answer:
7, 6, 3, 2, 1 -> Option A
Quick Check:
Pop order after operations = 7,6,3,2,1 [OK]
Hint: Pop removes last pushed; track pushes and pops stepwise [OK]
Common Mistakes:
Forgetting to remove popped elements
Mixing push and pop order
Ignoring elements still in stack after operations
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.