Vayu interview question

Explain the difference between a stack and a queue.

Interview Answer

Anonymous

27 Jul 2024

Answer: A stack is a linear data structure that follows the Last In First Out (LIFO) principle, where the last element added is the first to be removed. Common operations are push, pop, and peek. A queue, on the other hand, follows the First In First Out (FIFO) principle, where the first element added is the first to be removed. Common operations are enqueue (adding an element), dequeue (removing an element), and peek.