47
Algorithmic Complexity
public static int method1(int n){
int total = 0;
System.out.println(“Hello World”);
for(int i = 0; i < n; i++){ ( 1 ; n+1; n)
total += n;
}
for(int j = 0; j < 500; j++){
System.out.println(“Goodbye.”);
}
return total;
}
Check all components
-int i = 0 (this happens once)
-i < n (checked at start of each loop, account for stop)
-i ++ (once per loop at end)
-total += n (both add and assign, cost of 2 done n times)