for i in 1 to 8
for j in 1 to 4
// do somethingi on the x-axis
j on the y-axis
\(8\times 4=32\) steps total
for i in 1 to m
for j in 1 to n
// do somethingi on the x-axis, width n
j height n
\(m\times n=mn\) steps total
1=one unit of work, the "something"
for i in 1 to 5
for j in 1 to i
// do somethingi on the x-axis, width n
j height n
\(5+4+3+2+1=15=\frac{6\cdot 5}{2}\approx \frac{5\cdot 5}{2}\) steps total
for i in 1 to n
for j in 1 to i
// do somethingi on the x-axis, width n
j height n
\(n+\cdots +5+4+3+2+1=15=\frac{(n+1)\cdot n}{2}\approx \frac{n\cdot n}{2}\) steps total
for i in 1 to n
for j in 1 to i
// do somethingi on the x-axis, width n
j height n
for i in 1 to n
for j in i to n
// do somethingi on the x-axis, width n
j height n
If \(n\) has 10 digits then \(n^2\) has 20 digits.
20 digit number + 10 digit number is a 20 or 21 digit number.
The 10 digit number is huge but hardly makes a dent on the 20 digits!
Here \(\gg\) reads "much much bigger"
So area might miss some actual values, like \(n/2\) but those are minute impacts in the long run.
Area formula
"If \(n\) has 10 digits then \(n^2\) has 20 digits..... blah blah blah..."
Nice but vague and open to criticism.
Maybe you do care about 10 digit changes.
Better to use a limit explanation!
If \(f(n)\) is the real count and we want it to be a simpler \(\alpha n^k\) then up to some margin for error we accept \(f(n)\) as equal to \(\alpha n^k\), with possibly finitely many exceptions.
A LIMIT!
So we just need to find \(\alpha\). And since we know the most we do is independent choices for each loop, if we count the nested loops as \(k\) then \(\alpha n^k\) is the target.
1. Divide by highest power, here \(n^2\).
2. Take the limit as \(n\to \infty\) "goes towards infinity".
3. Highest power times this limit is your asymptote: \(\frac{1}{2}n^2\)
for s in 1 to m
// do this
for i in 1 to n
for j in 1 to i
// do thati width n
j height n
s length m
for s in 1 to 100
for t in 1 to s
// do this
for i in 1 to 40
for j in 1 to 50
for k in 1 to 20
// do thats width 100
t height 100
i 40
k 20
j 50
for i in 1 to n
for j in 1 to i
for k in 1 to j
// do somethingWhat on earth is the volume of that!?
Some of you might see you can copy this shape 6 times to make a cube.
By own work - Own work, Public Domain, https://commons.wikimedia.org/w/index.php?curid=11978055j
i
k
If you're that geometric you could answer \(\approx \frac{n^3}{6}\).
for i in 1 to 5
for j in 1 to i
for k in 1 to j
// do somethingWhat on earth is the volume of that!?
You don't need to know the exact
j
i
k
Since \(1\leq k\leq j\leq i\leq n\).
for i in 1 to 5
for j in 1 to i
for k in 1 to j
// do somethingj
i
k
for i_1 in 1 to n
for i_2 in 1 to i_1
...
for i_k in 1 to i_(k-1)
// do something\(k!=k\cdot (k-1)\cdots 2\cdot 1\)