s-99-54


A binary tree is either a childless vertex, or a vertex at most two children, which are binary trees.

In our notation, a vertex is indicated by a list of three elements, the first being the value assigned to the vertex, and the other two each being either:

Notice that our notation does not allow #f or any pair to be a leaf.

An example of a binary tree:

http://lcm.csa.iisc.ernet.in/dsa/img151.gif

It would be represented like so:

 '(1 (2 (4 8 9) 5) (3 6 7)) 

The solution is as follows:

 (define (binary-tree? t) 
   (if (not (pair? t)) 
     #t 
     (and (= (length (cdr t)) 2) 
          (binary-tree? (cadr t)) 
          (binary-tree? (caddr t)))))