Q: What is the difference between a queue and a stack?
-
A
A queue follows the Last-In-First-Out (LIFO) principle, while a stack follows the First-In-First-Out (FIFO) principle.
-
B
A queue allows elements to be inserted and removed from both ends, while a stack only allows elements to be inserted and removed from one end.
-
C
A queue is typically implemented using a linked list, while a stack is typically implemented using an array.
-
D
A queue is used for breadth-first search algorithms, while a stack is used for depth-first search algorithms.
B
Answer:
B
Explanation:
Answer: b) A queue allows elements to be inserted and removed from both ends, while a stack only allows elements to be inserted and removed from one end.
Explanation: The primary difference between a queue and a stack is that a queue allows elements to be inserted and removed from both ends, while a stack only allows elements to be inserted and removed from one end. Additionally, a queue follows the First-In-First-Out (FIFO) principle, while a stack follows the Last-In-First-Out (LIFO) principle.
Related Topic:
Share Above MCQ