Read this lesson as text

Analyzing Loop Complexity

Math for CS · Axiom Academy

LESSON Analyzing Loop Complexity Determining time complexity from loop structures The simplest case: a loop that runs n times. The loop body executes n times, each taking constant time. When loops are nested, multiply the complexities: Outer loop: n iterations Inner loop: m iterations per outer iteration Total: n × m iterations When inner loop bound depends on outer loop variable: When loop bounds divide or decrease: When the loop variable changes exponentially: Nested loops (independent bounds): or Nested loops (dependent bounds): Sequential loops: Add complexities

This is the written version of the interactive lesson above. See the full Math for CS course.