>>    




Homework Assignment

CS 121 (CS1)

< >
Homework 14   Due Friday, March 14, 2014
  1. Text questions on lists

      Lists, Exercises 12

      Hints

      12
      • The problem as stated is not completely defined, since it doesn't specify what to do if the word "sam" doesn't appear in the argument list. Here is a spec that addresses that question.

        countToSam

        One argument:
        A list of strings.
        Return:
        A non-negative integer, the number of elements up to and including the string "sam" in arg1. If the string "sam" does not occur in arg1, return 0.
        Example calls:
            countToSam(["i", "am", "sam.", "sam", "i", "am."]) --> 4
            countToSam(["i", "am", "sam", "sam", "i", "am"]) --> 3
            countToSam(["do", "you", "like", "green", "eggs", "and", "ham?"]) --> 0
            countToSam([]) --> 0
        
      • Use iteration (e.g., a for loop, since we know how many times to repeat because of the list arg1) or recursion.

  2. Iteration, if, and accumulators [hc]

      Iteration questions, 2j and 2k

  3. Recursion [hc]

      Recursion questions, 11e

  4. Trees [hc]

      Recursion questions, 12e and 12f

  5. String methods [hc]

      String questions, 1c

  6. Review [hc]

      Postponed

< >