Iteration
Repeating a block of code while a condition holds, and stopping when it no longer does. It's done with loops like for and while.
Example
To add 1 to 100, a loop repeats "add the next one" 100 times and gives 5,050.
Test yourself: Iteration
Iteration and recursion
What is iteration?
Adding 1 to 100 with a loop repeats "add the next one" 100 times and stops when the number goes past 100.
Iteration and recursion
2 nested loops going from 1 to n do about ___ operations.
For each of the n outer rounds, the inner one does n rounds: with n = 1,000, 1,000 × 1,000 = 1 million.
0/2
â–¶ PlayLessons that use it
What is an algorithm
You already use algorithms
Big O notation
How much does it grow?
Iteration and recursion
2 ways to repeat
Time complexity
Count steps, not seconds
Space complexity
How much memory it asks for
Stacks
Last in, first out
Binary search in depth
2 pointers closing in
Searching with a hash
From O(n²) to O(n) with a table
Selection sort
Picking the smallest, over and over
Quick sort
A pivot and 2 sides
Merge sort
Split in half and merge in order
Permutations
Every possible order
Subset sum
Groups that add up exactly
Dynamic programming
Solve each thing only once
Solving with DP
State, transition and borders
0-1 knapsack
Take it or leave it
Edit distance
How many changes separate 2 words
Largest container
Move the shorter board
Maximum product cutting
Cut into threes
SQL databases
Tables that relate
