Max function

Algorithm Run-times
// n >= 1
int Max(int A[], int n) {
int i;
int max = A[0];
for (i = 1; i < n; i++)
if (A[i] > max)
max = A[i];
return max;
}
I
I
S(n) is the number of statements executed in the worst
case.
Then S(n) = 4n + 1.
int Lin_search(int A[], int n, int key) {
int i;
for (i = 0; i < n; i++)
if (A[i] == key) return i;
return -1;
} /* Lin_search */
I
I
T (n) is the number of statements executed in the worst
case.
Then T (n) = 3n + 4.
void Sel_sort(int A[], int n) {
int i, j, min_loc, tmp;
for (i = 0; i < n-1; i++) {
min_loc = i;
for (j = i+1; j < n; j++)
if (A[j] < A[min_loc]) min_loc = j;
tmp = A[i];
A[i] = A[min_loc];
A[min_loc] = tmp;
}
/* Sel_sort */
}
I
I
U(n) is the number of statements executed in the worst
case.
Then U(n) = 2n2 + 7n 5.