Highlights
Question 1
Consider the following algorithm:
for ( i = 1; i<= 1.5n; i++)
print i
for ( i = n; i >= 1; i--)
print i
(a) What is the output when n = 2, n = 4?
(b) What is the time complexity?
Question 2
Consider the following algorithm:
int add_them (int n, int A[])
{
int i, j, k;
j = 0;
for ( i = 1; i<= n; i++)
j = j + A[i]
k = 1;
for ( i = 1; i<= n; i++)
k = k + k;
return j + k;
}
(a) If n = 5 and the array A contains 2, 5, 3, 7, and 8, what is the output?
(b) What is the time complexity of the algorithm?
(c) Try to improve the efficiency of the algorithm.© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.