Question 1: [5 Marks] What is the time complexity for each of the following:
a) int i = 0, b = 0;
b) int i = 0;
c) for (i = 0; i < n; i++) rand();
d) for (j = n; j > i; j--) a = a + 1 + j;
e) for (j = 0; j < m; j++) b = b + rand();
int i = 1;
int j = 2;
int sum;
sum = x * y;
cout << sum;
int i = 1;
while (i > 0) {
i += 1;
i /= 2;
}
int i = 1, j, k = 0;
for (i = n / 2; i <= n; i++) {
for (j = 2; j <= n; j++) {
k = k + n / 2;
}
}
2)
Question 2: [3 Marks] Apply the Selection sort algorithm on the following sequence: 90, 100, 70, 30, 99.
Question 3: [2 Marks] Reorder the following time complexity increasingly: Log2^8, Log2n, n^2, n^7, 10, Log2n.