Algorithm and Data Types- Programming Assignment Help

Download Solution Order New Solution

Programming Assignment Help:

Task:
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.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.