When to use Stacks vs Queues?

Real-Time Examples

A data structure that follows the LIFO (Last In First Out) principle. Think of it as a stack of plates - the last plate you put on the stack is the first one you take off.

Ready to master stacks and queues?

What is a Stack?

When to use Stack?

1. Browser History- The browser history uses a stack to keep track of the pages you have visited. Pressing the "back" button pops the last page from the stack and displays the previous page.

Ready to master stacks and queues?

2. Undo/Redo Functionality - In most applications, the undo/redo functionality uses a stack to store the changes made. Pressing the "undo" button pops the last change from stack & reverses it.

Ready to master stacks and queues?

Ready to master stacks and queues?

3. Call Stack - When you call a function in a program, it creates a new stack frame. This stack frame contains all data that function needs to execute. When function returns, stack frame is removed.

A linear data structure that follows First-In-First-Out (FIFO) principle. Think of it as a queue of people waiting in line at a store where first person in line is first to be served.

Ready to master stacks and queues?

What is a Queue?

1. Printing Queue - Printing queues use a queue data structure to keep track of print jobs. The jobs are added to the queue in the order they were received and printed in the same order.

Ready to master stacks and queues?

When to use Queues?

Ready to master stacks and queues?

2. Traffic Management - Traffic lights use queues to manage the flow of traffic. Cars are added to a queue & the traffic lights switch between queues to allow cars to move in a FIFO manner.

Ready to master stacks and queues?

3. Message Queue - In a messaging system, messages are added to a queue in the order they were received. This ensures that messages are processed in the order they were sent.

Join Scaler's FREE Masterclass on "Guide to Stacks and Queues" and explore the world of data structures. Learn crucial concepts and techniques under expert guidance.

Ready to explore the world of data structures?

Hurry up! 700+ people have already registered.

Starts On: March 23, 2023   Ends On: March 23, 2023   Duration: 8 - 11 PM

Event details-

So, what are you waiting for?

Step Up Your Game with InterviewBit Web Stories

Don't miss out on the chance to upskill yourself with IntervewBit's engaging web stories.