Skip to main content

Stacks and Queues

2 lessonsAbout 12 minutesBeginner

This part of the DSA Tutorial runs from Stacks in JavaScript through to Queues in JavaScript. There are 2 lessons here, and working through them takes about 12 minutes at a steady pace.

It follows on from Two Pointers and Sliding Window, so finish that first if you have not already — the examples below assume you are comfortable with it.

Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.

  1. 1Stacks in JavaScriptA stack is last in, first out. Learn how to build one on a JavaScript array, why push and pop are O(1), and the three problem shapes that are always a stack in disguise.
  2. 2Queues in JavaScriptA queue is first in, first out. Learn why array.shift() makes a queue quadratic, how to build an O(1) queue with a head pointer, and when you need a deque.