Where do we use them?

Stacks and Queues are not just academic exercises. They power the software you use every day.

1. Stack Applications (LIFO)

A. Browser History (Back/Forward)

  • Back Stack: Stores URLs you visited. Clicking “Back” pops from here and pushes to “Forward Stack”.
  • Forward Stack: Stores URLs you popped.

B. Undo / Redo in Text Editors

  • Every time you type, the state is pushed to an UndoStack.
  • Ctrl+Z pops the state and applies it.

C. Syntax Parsing (Compilers)

  • Checking balanced parentheses: ((a+b)) vs ((a+b).
  • XML/HTML tag matching.

2. Queue Applications (FIFO)

A. Task Scheduling (Operating Systems)

  • Processes wait in a Ready Queue for CPU time.
  • Round Robin scheduling uses a Circular Queue.

B. Web Server Request Handling

  • Requests (HTTP) arrive faster than the server can process.
  • They sit in a Request Queue (buffer).
  • If the queue fills up → 503 Service Unavailable.

C. Breadth-First Search (BFS)

  • Graph traversal algorithm that explores neighbors layer by layer.
  • Requires a Queue to store the “frontier” of nodes to visit next.

D. Rate Limiting (Leaky Bucket)

  • Network traffic is smoothed out by queuing packets.
  • If the bucket (queue) overflows, packets are dropped.