Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2019

Computer Science Department

Homework Assignment 29

Recursion

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


  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 29.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 when unsuccessful it returns the index at which the target would lie if inserted into the sorted list.  For example, search(['A', 'G', 'M', 'V'],'T') should return 3 as the 'T' would go between the 'M' and 'V' if inserted.


Michael Goldwasser
CSCI 1300/5001, Fall 2019
Last modified: Monday, 30 December 2019
Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring