DSA Lesson 32 of 33

DSA Complexity Review

Review common Big O complexities used in DSA.

Course Progress97%

Theory

Understanding complexity is essential when comparing algorithms. O(1) is constant time, O(log n) grows slowly, O(n) grows linearly, O(n log n) commonly appears in efficient sorting, and O(n²) grows quadratically.

Example

// O(1) console.log("Hello"); // O(n) for (let i = 0; i < 5; i++) { console.log(i); }

Expected Output

The first operation is constant time and the loop grows with input size.

Practice

Identify the time complexity of five different code snippets.

Interview Questions

  1. What is O(1)?
  2. What is O(n)?
  3. What is O(log n)?
  4. Why is complexity analysis important?