A Stack is a data structure that works like a stack of plates. You add (push) and remove (pop) items only from the top. It follows Last In, First Out (LIFO) order.
Click to reveal answer
beginner
What is a Queue and how does it work?
A Queue is a data structure like a line at a store. You add items at the back (enqueue) and remove from the front (dequeue). It follows First In, First Out (FIFO) order.
Click to reveal answer
intermediate
When should you use a Stack?
Use a Stack when you need to reverse things, track recent actions, or manage nested tasks. Examples: undo buttons, backtracking, parsing expressions.
Click to reveal answer
intermediate
When should you use a Queue?
Use a Queue when order matters and you want to process things in the order they arrive. Examples: task scheduling, breadth-first search, print jobs.
Click to reveal answer
beginner
What is the main difference between Stack and Queue?
Stack removes the most recent item added (LIFO). Queue removes the oldest item added (FIFO). This difference decides when to use each.
Click to reveal answer
Which data structure uses Last In, First Out (LIFO) order?
AStack
BQueue
CLinked List
DTree
✗ Incorrect
Stack follows LIFO, meaning the last item added is the first to be removed.
Which data structure should you use to process tasks in the order they arrive?
AStack
BQueue
CGraph
DSet
✗ Incorrect
Queue processes items in FIFO order, so tasks are handled in arrival order.
Which of these is a common use case for a Stack?
APriority queue
BPrint job scheduling
CUndo feature in text editors
DBreadth-first search
✗ Incorrect
Undo uses Stack to reverse recent actions (LIFO).
What operation adds an item to the back of a Queue?
APush
BDequeue
CPop
DEnqueue
✗ Incorrect
Enqueue adds an item to the back of the Queue.
If you want to explore nodes level by level in a graph, which data structure is best?
AQueue
BStack
CArray
DHash Map
✗ Incorrect
Queue supports breadth-first search which explores nodes level by level.
Explain the main difference between a Stack and a Queue and give one example use case for each.
Think about how items are added and removed in each.
You got /3 concepts.
Describe a real-life situation where using a Queue is better than a Stack and why.
Imagine waiting in line at a store.
You got /3 concepts.
Practice
(1/5)
1. Which data structure should you use when you need to process items in the exact order they arrive, like customers waiting in line?
easy
A. Queue, because it processes items in First-In-First-Out order
B. Stack, because it processes items in Last-In-First-Out order
C. Array, because it allows random access
D. Tree, because it organizes data hierarchically
Solution
Step 1: Understand the order requirement
Processing items in the exact order they arrive means First-In-First-Out (FIFO).
Step 2: Match data structure to FIFO
Queue follows FIFO, so it fits the requirement perfectly.
Final Answer:
Queue, because it processes items in First-In-First-Out order -> Option A
Quick Check:
FIFO = Queue [OK]
Hint: FIFO means use Queue, like a line at a store [OK]
Common Mistakes:
Confusing FIFO with LIFO
Choosing Stack for order-sensitive tasks
Thinking arrays maintain insertion order automatically
2. Which of the following is the correct way to push an element onto a stack in Go using a slice named stack?
easy
A. stack = append(element, stack...)
B. stack = stack[:len(stack)-1]
C. stack = stack + element
D. stack = append(stack, element)
Solution
Step 1: Recall how to add elements to a slice
In Go, append(slice, value) adds value to the end of slice.
Step 2: Identify correct push operation
Pushing onto a stack means adding to the top, which is the end of the slice, so stack = append(stack, element) is correct.
Final Answer:
stack = append(stack, element) -> Option D
Quick Check:
Push = append to slice end [OK]
Hint: Use append to add on top of stack slice [OK]
Common Mistakes:
Using slicing to add elements instead of append
Trying to add element at the front incorrectly
Using + operator which is invalid for slices
3. What will be the output of the following Go code snippet?