Assigned: Friday, January 28, 2000
Due: Friday, February 4, 2000, in the beginning of class.
Define the function RotateLeft1, which takes a list as its argument and returns a new list in which the former 1st element becomes the last. For example:
(RotateLeft1 '(a b c d)) -> (b c d a) (RotateLeft1 '(a)) -> (a) (RotateLeft1 '()) -> ()
Define RotateRight1 like RotateLeft1 except that it rotates the list in the other direction:
(RotateRight1 '(a b c d)) -> (d a b c) (RotateRight1 '()) -> ()
Now define Rotate, as a function of two arguments, a list L and an integer N. It returns a new list formed by rotating L N times to the right if N>0 and to the left if N<0. Examples are:
(Rotate '(one two three four five) 2) -> (four five one two three) (Rotate '(one two three infinity) -3) -> (infinity one two three) (Rotate '( () (()) ((())) ) 0) -> (() (()) ((())))
In class we defined a function COUNTATOMS which computes the number of atoms in a list. Write a similar function countCells which computes the number of list cells a list uses. An atom uses no cells. The empty list (i.e., ()) uses no cells. A list uses one cell for each of its members in addition to the cells each of its members uses. For example:
(countCells '(one two three four five)) -> 5 (countCells '(one (two) three four five)) -> 6 (countCells '(define (square x) (* x x)) -> 8 (countCells '()) -> 0 (countCells 'foo) -> 0
Implement a function called binary-search that searches a binary tree for the presence of a node. The function should take as parameters a tree and a goal node. The function should return the node if found, and false otherwise. Make sure you tell us which tree representation you use and give us an example of a tree as part of the comments for this function.