DSA Lesson 11 of 33

Stack

Learn the LIFO data structure and its common applications.

Course Progress33%

Theory

A stack follows the Last In, First Out principle. The last element inserted is the first element removed. Common stack operations are push and pop. Stacks are used in function calls, undo operations, expression evaluation and browser history.

Example

const stack = []; stack.push(10); stack.push(20); stack.push(30); console.log(stack.pop()); console.log(stack);

Expected Output

30 is removed first because the stack follows LIFO.

Practice

Implement a stack using an array with push and pop operations.

Interview Questions

  1. What is a stack?
  2. What does LIFO mean?
  3. What are push and pop?
  4. Where are stacks used?