Guided Practice 8.2

True/False: Which of the following is a valid halting measure for even-elements, and why?

  1. the largest element of lst
  2. the number of distinct elements of lst
  3. the sum of the elements of lst
  4. the length of lst

Answers:

  1. False. If the largest element is far down in the list, taking (rest (rest lst)) will not change the value of the largest element. For example, consider lst = (list 12 11 5 17 12 11). The largest element in lst is 17, but the largest element in (rest (rest lst)) is still 17.
  2. False. If the first two elements are both duplicated farther down in the list, then taking (rest (rest lst)) will not change the number of distinct elements.
  3. False. If the first two elements are both 0, then the sum of the elements will not change.
  4. True. The length of a list is always a non-negative integer, and the length decreases by two at every recursive call.

Last modified: Sun Oct 19 15:18:09 Eastern Daylight Time 2014