August 19, 2024

P58 - Generate and test paradigm

Apply the generate-and-test paradigm to construct all symmetric, completely balanced binary trees with a given number of nodes.

Example:* (sym-cbal-trees-print 5)(X (X NIL (X NIL NIL)) (X (X NIL NIL) NIL))(X (X (X NIL NIL) NIL) (X NIL (X NIL NIL)))...

How many such trees are there with 57 nodes? Investigate about how many solutions there are for a given number of nodes. What if the number is even? Write an appropriate function.

lisp

(load "p55.lisp")
(load "p56.lisp")

(defun sym-cbal-trees-print (n)
  (dolist (tree (cbal-tree n))
    (if (symmetric tree)
	(print tree)
      nil
      )
    )
  )
Be first to comment
Leave a reply