CS212 Exams
Fall 1996 - Prelim 1

Recursion


This problem is concerned with writing a procedure that produces a list of running sums given a nonempty list of numbers. A running sum is the sum of the elements thus far in the list. For example:
(running-sum '(1 2 3 4)) --> (1 3 6 10)

(running-sum '(7)) --> (7)

Write a recursive procedure to compute running-sum, which runs in time linear in the length of the list. Your answer may not use any helper procedures either by defining other top-level procedures or by having internal defines (in particular you cannot use any for of let or any other way of creating a lambda inside a lambda).

As with this entire exam, you may not use set!.







Solution

Return to CS 212 Prelim 1 - Fall 1996