2. To write a procedure that traverses (a list representation of) a tree.
(number-of-occurrences 5 (list 2 5 7 6 5 4 3 5 2 7 6 8 5 3))
will return 4. If the number does not appear at all in the list, 0 will
be returned.
2. Define a procedure leaf-in-tree? that takes two arguments. The first argument is a number, and the second argument is a list representation of a tree, all of whose leaves are numbers. If the number (first argument) appears anywhere as a leaf in the tree, leaf-in-tree? returns #t; otherwise, it returns #f. For example, if
(define x (list (list 3 5) (list (list 2 5) 3) 6 (list (list 4))))
(leaf-in-tree? 5 x)
(leaf-in-tree? 7 x)
is executed,
the value of x will be ((3 5) ((2 5) 3) 6 ((4))), the
call to (leaf-in-tree? 5 x) will return #t and the call
to (leaf-in-tree? 7 x) will return #f.
Summit your definitions of these two procedures to the Automated Tester and click on the Confirm butten when you get a PASS.