2) Analyze the below algorithm to determine its theta notation, ( ).
void exchangesort (int n, keytype S[ ])
{
index i, j;
for ( i = 1; i <= 1; i++) {
for ( j = i + 1; j <= n; j++) {
if ( S[j] < S[i] ) {
temp = S[j];
S[j] = S[i];
S[i] = temp;
} // end if
} // end for j
} // end for i
}
3) Analyze the below algorithm to determine its theta notation, ( ).
i := n
while i > 0 do
for j = 1 to n do
k := 1
while k < i do
< something of >
k := k * 2
end while
end for
i := i / 2
end while
4) For sequential search, what is the best-case time complexity B (n)?
5) For sequential search, what is the worst-case time complexity W (n)?
6) If the probability of a successful sequential search is p, then what is the probability on an unsuccessful search?
7) If the probability of a successful sequential search is p, then what is the probability of finding the target value at a specific index in the array?
Write a summation for the average number of comparisons.
8) What is the average time complexity, A (n)?
9) For binary search, what is the best-case time complexity B (n)?
10) For binary search, what is the worst-case time complexity W (n)?
11) For binary search, develop a summation for the average number of comparisions? (you do not necessarily need to solve it)