Guided Practice 8.2
True/False: Which of the following is a valid halting measure for even-elements, and why?
- the largest element of lst
- the number of distinct elements of lst
- the sum of the elements of lst
- the length of lst
Answers:
- 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.
- 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.
- False. If the first two elements are both 0, then the sum of the elements will not change.
- True. The length of a list is always a non-negative integer, and the length decreases by two at every recursive call.
Last modified: Mon Oct 16 15:17:39 Eastern Daylight Time 2017