Stacks & Queues
Stacks and queues are two types of data structures.
Data structures such as stacks and queues are used to store lists of elements.
According to FIFO (first-in, first-out), queues operate in a sequential manner.
As the name implies, elements are enqueued the same way they arrive and dequeued the same way they depart. The first element in is the first one out.
In contrast, stacks operate in the opposite direction. Their method is called "last-in, first-out" (LIFO).
Element recovery is thus possible in reverse order.
Imagine stacks like stacks of pancakes. As the last pancake, the top-most pancake was retrieved last.
A linked list or array is usually executed alongside stacks and queues.
Stacks and queues are critical components of many basic algorithms in software engineering.
The most common stack and queue interview questions
These general tasks may be requested of you during your interview. Please use the language that you are most comfortable with.
The concepts
- Enqueuing
- Dequeuing
- Pushing items to a stack
- Popping items from a stack
- Looping over queues and stacks
- Peeking the top of a stack
- Stack reversal
- Getting a stack's size
- Getting a queue's size