Data Structures and Algorithms

Lab 02 - Recursion

Exercise 1.
Write a program that takes two positive integers, m and n, as input, then uses a recursive algorithm to compute the product of m and n using only addition and subtraction.

Exercise 2.
Write a program using a recursive algorithm to print all sub-sets (each subset appears only one time) of the set [1,2,...n], where n is an integer that user must enter.

Exercise 3.
Write a program that takes an array A of n elements and integers i and j (0 <= i < j < n) as inputs, then uses a recursive algorithm to reverse of the elements in A starting at index i and ending at j.

Exercise 4.
Write a program that takes a sequence of n integers as input, them uses 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.