Compute for the time complexity with solution int cTotal(int n){ int i; int total=0; for (i=1; i <= n ; i++)
Posted: Mon Mar 21, 2022 4:50 pm
Compute for the time complexity with solution
int cTotal(int n){
int i;
int total=0;
for (i=1; i <= n ; i++)
total += i;
return total;
}
• What is T(n) [worst case senario]
• What is T(n) if i<=n change to i<n
• What is T(n) if instead of returning the sum of n, it will
return only the sum of all even numbers from 1 to n [worst case
senario]
int cTotal(int n){
int i;
int total=0;
for (i=1; i <= n ; i++)
total += i;
return total;
}
• What is T(n) [worst case senario]
• What is T(n) if i<=n change to i<n
• What is T(n) if instead of returning the sum of n, it will
return only the sum of all even numbers from 1 to n [worst case
senario]