Learn / macOS

Derive time and space complexity in Big O Lab

Estimate growth, justify your answer, and compare your reasoning with the walkthrough.

Big O Lab with an exercise, complexity claims, and reasoning fields.
Big O Lab with an exercise, complexity claims, and reasoning fields. Select the image to enlarge.
  1. Define the input size

    Name each variable and identify what operation repeats. Separate the given input from additional storage.

    Example

    For a graph traversal, V counts vertices and E counts edges. For binary search, n counts sorted input elements.

  2. Enter a claim and justify it

    Enter time and space, and explain loops, recursion, and storage. State the relevant case.

    Example

    Iterative binary search halves the remaining interval each step. Worst-case time is O(log n). It uses O(1) auxiliary space for a fixed number of variables.

  3. Check, compare, and transfer

    Check the answer, inspect the reference derivation and growth visualization where available, then try the same explanation in Coding’s Complexity phase.

    Example

    Two separate passes over n items cost O(n). A full pass nested inside another costs O(n²). Explain what an inner loop does before multiplying.

Check your work

Your explanation defines the input size and identifies the operation and storage that dominate growth.

Try it yourself

Choose a loop example or write this variation in your notes. For each i from 0 through n − 1, the inner loop visits j from 0 through i. Enter a time and auxiliary space claim.

What to look for
The inner loop runs 1 + 2 + … + n times, giving Θ(n²) time. If the loops use a fixed number of variables and retain no growing collection, auxiliary space is Θ(1).