Date 2026-06-30
Track Algo & Data Structures
Type Lesson
Learning Objective Understand the fundamental concept of algorithmic complexity and Big O notation for evaluating algorithm performance
algorithmscomplexitybig-ofundamentals

Introduction to Algorithms

An algorithm is a finite, ordered sequence of well-defined instructions for solving a problem. Every program you write is a composition of algorithms.

Why Complexity Matters

When choosing an algorithm, we care about two resources:


We describe this growth with Big O notation, which captures the worst-case upper bound.

Common Complexities (best → worst)

NotationNameExample
O(1)ConstantArray index lookup
O(log n)LogarithmicBinary search
O(n)LinearLinear scan
O(n log n)LinearithmicMerge sort
O(n²)QuadraticBubble sort
O(2ⁿ)ExponentialNaïve Fibonacci

Key Insight: Drop Constants and Lower Terms

Big O strips away constants and lower-order terms because they become irrelevant at scale:

Practice Prompt

Given this function, what is its time complexity?

def find_pair_sum(nums, target):
    seen = set()
    for n in nums:
        if target - n in seen:
            return True
        seen.add(n)
    return False

Answer: O(n) time, O(n) space — single pass with a hash set.

Next Up

With complexity intuition in hand, you're ready to compare sorting algorithms and understand why merge sort beats bubble sort on large inputs.