Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main difference between a Queue and a Stack?
A Queue follows First-In-First-Out (FIFO) order, meaning the first item added is the first removed. A Stack follows Last-In-First-Out (LIFO) order, meaning the last item added is the first removed.
Click to reveal answer
beginner
In C#, which method adds an item to a Queue?
The Enqueue() method adds an item to the end of the Queue.
Click to reveal answer
beginner
How do you remove the top item from a Stack in C#?
Use the Pop() method to remove and return the item at the top of the Stack.
Click to reveal answer
intermediate
What happens if you call Dequeue() on an empty Queue in C#?
It throws an InvalidOperationException because there are no items to remove.
Click to reveal answer
intermediate
Explain the behavior of Peek() method in both Queue and Stack.
The Peek() method returns the next item to be removed without removing it. For a Queue, it returns the item at the front. For a Stack, it returns the item at the top.
Click to reveal answer
Which method adds an element to the top of a Stack in C#?
APop()
BEnqueue()
CPush()
DDequeue()
✗ Incorrect
The Push() method adds an element to the top of the Stack.
What order does a Queue follow?
AFirst-In-First-Out (FIFO)
BLast-In-First-Out (LIFO)
CRandom order
DSorted order
✗ Incorrect
A Queue follows First-In-First-Out (FIFO) order.
What does the Pop() method do in a Stack?
ARemoves and returns the top item
BReturns the bottom item without removing
CAdds an item to the bottom
DRemoves the first item added
✗ Incorrect
Pop() removes and returns the top item of the Stack.
Which method removes the front item from a Queue?
APop()
BPush()
CPeek()
DDequeue()
✗ Incorrect
Dequeue() removes and returns the front item of the Queue.
What will happen if you call Peek() on an empty Stack?
AReturns null
BThrows InvalidOperationException
CReturns default value
DRemoves an item
✗ Incorrect
Calling Peek() on an empty Stack throws InvalidOperationException.
Describe how Queue and Stack differ in the order they remove items.
Think about a line of people versus a stack of plates.
You got /4 concepts.
Explain the purpose of the Enqueue, Dequeue, Push, and Pop methods in C# collections.
Match methods to adding or removing items in Queue or Stack.
You got /4 concepts.
Practice
(1/5)
1. Which data structure removes elements in the order they were added, like a line at a grocery store?
easy
A. Array
B. Stack
C. Dictionary
D. Queue
Solution
Step 1: Understand FIFO behavior
A queue removes elements in the order they were added, called First-In-First-Out (FIFO).
Step 2: Match behavior to real-life example
A line at a grocery store is FIFO, so the queue matches this behavior.
Final Answer:
Queue -> Option D
Quick Check:
FIFO = Queue [OK]
Hint: FIFO means first in, first out like a queue line [OK]
Common Mistakes:
Confusing stack with queue
Thinking stack is FIFO
Mixing array behavior with queue
Assuming dictionary has order
2. Which of the following is the correct way to add an item to a Stack in C#?
easy
A. stack.Push(item);
B. stack.Enqueue(item);
C. stack.Add(item);
D. stack.Insert(item);
Solution
Step 1: Recall Stack method names
In C#, Stack uses Push() to add items on top.
Step 2: Identify correct method
Enqueue is for Queue, Add and Insert are not Stack methods.
Final Answer:
stack.Push(item); -> Option A
Quick Check:
Push adds to Stack [OK]
Hint: Use Push() to add to Stack, Enqueue() for Queue [OK]
Common Mistakes:
Using Enqueue() on Stack
Using Add() or Insert() which don't exist
Confusing Stack and Queue methods
Syntax errors with method calls
3. What is the output of this C# code?
var stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
Console.WriteLine(stack.Pop());
Console.WriteLine(stack.Peek());
medium
A. 3\n2
B. 1\n2
C. 2\n3
D. 3\n3
Solution
Step 1: Trace Push operations
Stack after pushes: bottom=1, middle=2, top=3.
Step 2: Execute Pop and Peek
Pop() removes and returns top (3). Peek() returns new top (2) without removing.
Final Answer:
3\n2 -> Option A
Quick Check:
Pop=3, Peek=2 [OK]
Hint: Pop removes top, Peek shows top without removing [OK]
Common Mistakes:
Mixing Pop and Peek results
Assuming FIFO order
Confusing stack order
Forgetting Pop removes item
4. Identify the error in this C# code using Queue:
var queue = new Queue<string>();
queue.Push("apple");
queue.Enqueue("banana");
Console.WriteLine(queue.Dequeue());