You are on page 1of 1

Assignment 1

1. Do a self-study on Space Complexity of algorithms and, write an essay on what you have
understood about the same, giving ample examples.

2. Refer to the topic 2.3 in the textbook by Anany Levitin for reference and calculate the time
complexities of the following non-recursive algorithms:
a. Element uniqueness check whether all the elements in a given array of n elements are
distinct.
b. Matrix multiplication
c. Number of binary digits in the binary representation of a positive decimal integer.
d. Sequential Search.

3. Consider the following algorithm:


ALGORITHM Mystery(n)
//Input: A nonnegative integer n
S 0
for i 1 to n do
S S + i i
return S
a. What does this algorithm compute?
b. What is its basic operation?
c. How many times is the basic operation executed?
d. What is the efficiency class of this algorithm?
e. Suggest an improvement, or a better algorithm altogether, and indicate its efficiency
class. If you cannot do it, try to prove that, in fact, it cannot be done.

4. Refer to the topic 2.4 in the textbook by Anany Levitin for reference. Arrive at a recurrence
relation with an appropriate initial condition and solve the recurrence or, at least, ascertain the
order of growth of its solution of the following recursive algorithms:
a. Tower of Hanoi
b. Recursive version of the problem mentioned in the question 2.c above.
c. Fibonacci numbers

5. Consider the following recursive algorithm for computing the sum of the first n cubes: S(n) = 13 +
23 + . . . + n3:
ALGORITHM S(n)
//Input: A positive integer n
//Output: The sum of the first n cubes
if n = 1 return 1
else return S(n 1) + n n n
a. Set up and solve a recurrence relation for the number of times the algorithms basic
operation is executed.
b. How does this algorithm compare with the straightforward non-recursive algorithm for
computing this sum?

You might also like