Homework Assignment

Recursion

Overview

Topic: Recursion
Related Reading: Chapters 26 and 27
Due:

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


Problems to be Submitted (20 points)

  1. (10 points)

    The chapter provides an implementation of OurList.index that accepts a single value as a parameter, with the public syntax data.index(val) responsible for returning the index of the first occurrences of the given value on the list (presuming it is found).

    The index method of the built-in list class accepts an additional optional parameter that is an index at which the search for the value should begin, as in data.index(val, k)

    Provide a new implementation of the OurList.index that includes such an optional parameter (with the default value of 0). You may assume that the parameter is a nonnegative integer.

  2. (10 points)

    Our implementation of the function search(lexicon, target) (Figure 27.4) was written to return a boolean result designating whether the target was contained in the list. Rewrite that function (and the corresponding _search utility) so that it returns the index at which the target is found in the list, when the search is successful, and the index at which the target would lie if inserted into the sorted list.


Last modified: Wednesday, 05 December 2018