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 (enqueue) items at the back and remove (dequeue) items from the front. 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 handle nested tasks. Examples: undo buttons, backtracking, expression evaluation.
Click to reveal answer
intermediate
When should you use a Queue?
Use a Queue when order matters and you want to process items in the order they arrive. Examples: task scheduling, breadth-first search, printer queues.
Click to reveal answer
beginner
What is the main difference between Stack and Queue?
Stack removes the most recent item added (LIFO), while Queue removes the oldest item added (FIFO). This difference decides when to use each.
Click to reveal answer
Which data structure follows Last In, First Out (LIFO)?
ALinked List
BQueue
CStack
DTree
✗ Incorrect
Stack follows LIFO, meaning the last item added is the first to be removed.
Which data structure is best for processing tasks in the order they arrive?
AStack
BQueue
CGraph
DHash Table
✗ Incorrect
Queue processes items in First In, First Out (FIFO) order, so tasks are handled in arrival order.
Which of these is a common use case for a Stack?
AUndo feature in text editors
BTask scheduling
CPrinter queue
DBreadth-first search
✗ Incorrect
Undo features use Stack to reverse recent actions (LIFO).
What operation adds an item to a Queue?
AEnqueue
BPop
CDequeue
DPush
✗ Incorrect
Enqueue adds an item to the back of the Queue.
Which data structure would you use for breadth-first search (BFS)?
AArray
BStack
CSet
DQueue
✗ Incorrect
BFS uses Queue to explore nodes level by level in FIFO order.
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.
Imagine waiting in line at a store.
You got /3 concepts.
Practice
(1/5)
1. Which data structure should you use when you want to process items in the exact order they arrive, like people standing in a line at a ticket counter?
easy
A. Queue
B. Stack
C. Tree
D. Graph
Solution
Step 1: Understand the order of processing
People in line are served in the order they arrive, which is First In First Out (FIFO).
Step 2: Match the data structure to FIFO
A Queue follows FIFO, so it fits this scenario perfectly.
Final Answer:
Queue -> Option A
Quick Check:
FIFO = Queue [OK]
Hint: Use Queue for FIFO order, like lines [OK]
Common Mistakes:
Confusing Stack with Queue
Thinking Stack processes in arrival order
Choosing Tree or Graph for simple order
2. Which of the following is the correct way to add an element to a stack in Python using a list named stack?
easy
A. stack.enqueue(element)
B. stack.push(element)
C. stack.append(element)
D. stack.insert(0, element)
Solution
Step 1: Recall Python list methods for stack
Python lists use append() to add elements at the end, simulating stack push.
Step 2: Check other options
enqueue() and push() are not list methods; insert(0, element) adds at front, not top of stack.
Final Answer:
stack.append(element) -> Option C
Quick Check:
Stack push = append() in Python [OK]
Hint: Use append() to push on Python list stack [OK]
Common Mistakes:
Using enqueue() which is for queues
Using push() which is not a Python list method
Inserting at index 0 which is queue front
3. What will be the output of the following Python code?