Counting Nested Loops
Counting Nested Loops
- The following rules of thumb usually apply
- A single loop yields a linear function of n
- A doubly-nested loop yields a function of n2
- A triply-nested loop yields a function of n3
- Be Careful when applying these rules
For i := 1 to n do
For j := 1 to n do
a := a + 1
End For
End For
Total Operations = n2
For i := 1 to n do
For j := 1 to 3 do
a := a + 1
End For
End For
Total Operations = 3n