Course Home | Homework | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science A220/P126
Data Structures and Object-Oriented Programming

Michael Goldwasser

Spring 2005

Dept. of Math & Computer Science

Homework Assignment 02

Recursion

Contents:


Overview

Topic: Recursion
Related Reading: Ch. 2.5.1 and 4.1
Due: Monday, 31 January 2005, 1:10pm

Please make sure you adhere to the policies on academic integrity.


Practice Problems


Problems to be Submitted (20 points)

  1. (10 points)

    Ch 2.5.1 describes a recursive procedure drawTicks(int tickLength). For this problem, we are interested in determining the number of lines of output which are generated by a call drawTicks(L) for a given integer L, including all of the recursive calls it generates.

    1. As a function of L, how many lines of output are generated?
      (Hint: You might wish to try out a few small values by hand)

    2. Give a proof of your result!

  2. (10 points)

    Give a C++ implementation of a recursive algorithm for finding the maximum element in an array A of n elements? For the sake of outward appearance, you must support a routine with signature as follows:

    int max(int A[], int n)
    though certainly you may choose to define an additional routine if you wish.

    Note: You do not necessarily need to type/execute this code. Doing it on paper is fine. But we ask that you use C++ in describing your answer for the sake of precision.


Extra Credit

  1. (2 points)

    Creativitiy Exercise C-4.3 (page 197) of the text (though you need not discuss the running time).


Michael Goldwasser
CS A220/P126, Spring 2005
Last modified: Wednesday, 02 February 2005
Course Home | Homework | Programming | Schedule & Lecture Notes | Submit