Data Structures and Algorithms

Lab 02 - Recursion & Lists

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.

Lists

Exercise 5. Array list Complete the implementation of an array-based list in alist-incomplete.cpp. You can add other methods that you find necessary.
You should use function main to test all the methods.

Exercise 6 - Singly linked list Complete the implementation of singly linked list in slist-incomplete.cpp. You can add other methods that you find necessary.
You should modify function main to test all the methods.

Exercise 7 - Doubly linked list Implement a doubly linked list data structure that provides the same functions and the same interface as the class SList in Question 2.