
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Samet; Class: Data Structures; Subject: Computer Science; University: University of Maryland; Term: Fall 2007;
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

The following exercises are designed to test your understanding of recursion. The functions are defined using a variant of LISP known as meta-LISP. In order to aid your understanding, the function defined in problem 1 is identical to the one below:
drop(x) = if null x then nil else (car x) cons drop(cdr x)
The idea is that a x = car x d x = cdr x n x = null x at x = atom x a.b = a cons b = a cons nil = a list whose single element is a a*b = concatenate lists a and b (i.e. append list b to list a) reverse[x] = reverses the top level list x. For example reverse[(A B C)] = (C B A). But reverse[((A B C)(D E))] = ((D E)(A B C)).
r5[x] โ if n x โจ n d x then x else [a r5[d x]]. r5[a x. r5[d r5[d x]]].
Compute r5[(A B C D)]. What does r5 do in general. Needless to say, this is not a good way of computing this function even though it involves no auxiliary functions.