Data Structures and Algorithms

Homework 03 - Recursion

(adapted from Pham Bao Son's DSA-09s2)

Question 1.

  1. Describe a recursive algorithm for finding the maximum element in an array of n integers.
  2. Describe a recursive algorithm to compute the product of two positive integers, m and n, using only addition and subtraction.

Question 2.
Describe a recursive algorithm to print all sub-sets (each subset appears only one time) of set of n integers.

Question 3.
An array A of n elements and integers i and j (0 <= i < j < n). Describe a recursive algorithm to reverse of the elements in A starting at index i and ending at j.

Question 4.
Given a sequence of n integer stored in an array, describe a recursive algorithm to print out a subsequence of non-decreasing elements with maximum length. A subsequence may contain non-consecutive elements but they should be ordered in the same way as the original sequence.