Day 22 - Introduction to Big O Notation

Day 22: Introduction to Big O Notation

Learning Objectives

Essential Questions

Materials Needed

Vocabulary

Procedure (50 minutes)

Opening (8 minutes)

  1. Review and Connection (3 minutes)

    • Review algorithm efficiency concepts from previous lesson
    • Connect to today's focus on formally classifying algorithm efficiency
  2. Warm-up Activity (5 minutes)

    • Show graphs of different growth rates (constant, linear, quadratic, etc.)
    • Ask students to match them to algorithms they've seen
    • Introduce the need for a standardized way to describe these patterns

Main Activities (32 minutes)

  1. Lecture: Big O Notation and Common Complexities (12 minutes)

    • Define Big O notation as a way to classify algorithms by their growth rate
    • Explain that Big O describes the worst-case scenario as input size increases
    • Introduce common Big O classifications:
      • O(1) - Constant time: execution time doesn't depend on input size
        • Examples: accessing an array element, simple calculations
      • O(log n) - Logarithmic time: execution time grows logarithmically
        • Examples: binary search
      • O(n) - Linear time: execution time grows proportionally to input size
        • Examples: linear search, simple traversals
      • O(n log n) - Linearithmic time: common for efficient sorting
        • Examples: merge sort, quicksort
      • O(n²) - Quadratic time: execution time grows with square of input size
        • Examples: nested loops, simple sorting algorithms
      • O(2^n) - Exponential time: execution time doubles with each additional input
        • Examples: recursive fibonacci, brute force solutions
    • Explain how to determine Big O for simple algorithms:
      • Count nested loops
      • Identify dominant terms
      • Focus on growth rate, not constants
    • Discuss the difference between efficient and inefficient algorithms
    • Explain why polynomial time algorithms are considered "reasonable"
  2. Demo: Determining Big O for Simple Algorithms (8 minutes)

    • Walk through examples of determining Big O complexity:
      • Accessing an element in an array: O(1)
      • Linear search in a list: O(n)
      • Nested loops processing all pairs: O(n²)
      • Binary search in a sorted list: O(log n)
    • Show how to analyze code to determine its complexity
    • Demonstrate how to identify the dominant term
    • Illustrate how different algorithms scale with input size
    • Show graphs of different complexity classes
  3. Hands-on: Analyzing Algorithms for Time Complexity (12 minutes)

    • Students work individually or in pairs
    • Provide students with several algorithm implementations
    • Students determine the Big O complexity for each algorithm
    • Students justify their classifications
    • Have students match algorithms to their complexity classes
    • Encourage students to create or modify algorithms to achieve specific complexities

Closing (10 minutes)

  1. Activity: Matching Algorithms to Their Big O Classifications (5 minutes)

    • Provide students with a set of algorithm descriptions
    • Students classify each algorithm according to its Big O complexity
    • Discuss the classifications as a class
    • Address any misconceptions or questions
    • Highlight how Big O helps compare algorithms at scale
  2. Exit Ticket and Preview (5 minutes)

    • Students determine the Big O complexity of given algorithms
    • Preview that next class will focus on the final project planning and design

Assessment

Differentiation

For Advanced Students

For Struggling Students

Homework/Extension

Teacher Notes