|
Here are some problems to practice on, using the same three higher-order procedures in problem 1 of the Midterm.
- Check whether a given symbol occurs in a given list.
- Check whether a given symbol occurs in a given binary tree.
- Add up all of the numbers in a list/tree, ignoring things that are not numbers.
- Reverse a list.;
- Concatenate two lists.
- Given a list of pairs of numbers, produce the list of sums of the pairs.
- Given a list of pairs of numbers, produce the sum of the products of the pairs.
- Check a binary tree to see whether it consists entirely of representations of nested lists. That is, whether it can be printed out with no dots. This is a bit tricky. It requires a third value besides
#t and #f.
- Convert a binary tree to nested lists of length two, each list representing a dotted pair in the original tree.
- Delete every number less than a given amount from a list of numbers.
- Replace every number less than a given amount at the leaves of a binary tree by
(), and collapse every subtree all of whose leaves are () into a single ()
- Inspect a list of numbers, and produce a pair
(ordered? max), where ordered? is #t if the numbers are in strictly increasing order from left to right, and #f otherwise, and where max is the maximum of the numbers in the tree. I don't think you can produce ordered? correctly without some additional information.
- Do almost the same thing, but produce a pair
(ordered? min).
- Do it again, producing
(ordered? lastelt), and again producing (ordered? firstelt).
- Compute the pair
(minmax, maxmin) for a binary tree with numbers at the leaves. These are standard game-theoretic values. It's not possible to compute one without the other using the given higher-order functions.
Some of these are substantially harder than the ones on the midterm. The midterm problems are similar to the easiest ones in this practice list.
Mike O'D.
|