For each of the code segments below determine an equation fo
For each of the code segments below, determine an equation for the worst-ease computing time T(n) (expressed as a function of n, i.e. 2n + 4) and the order of magnitude (expressed using big O notation, i.e. O(n)).//Matrix addition for (int i = 0; i
Solution
HI, I have answered first four part.
Please let me know in case of any issue.
b)
T(n) = n + n + n + ... ntimes
= n*n
Big-O = O(n^2)
c)
T(n) = T(n) = n + n + n + n + ....+n^2 times
= n*n*n
Big-O = O(n^3)
d)
T(n) = (n-1) + (n-1) + (n-1) ...(n-1)times
= (n-1)(n-1) = n^2 -2n + 1
Big-O = O(n^2)
e)
while (n >= 1)
n /= 2;
T(n) = T(n/2) + O(1)
= [N]/2 + [(N/2)]/2 + [((N/2)/2)]/2.....
= N/21 + N/22 + N/23 +..... + N/2x …..
Big-O = O(logn)
