I am working on question 18.3 in the Simply Scheme program (questions at bottom of page): https://people.eecs.berkeley.edu/~bh/ssch18/trees.html The problem is to write depth, a procedure that returns the number of nodes in the longest branch of a tree. So far I have written:
(define (depth-count node)
(cond ((null? (children node))
1)
(else
(reduce + (depth-count (children node)))))
So I have the base case as a 'leaf' node - no children. I want to + 1 for each parent node to a leaf, then compare nodes at the same depth and take the node with the max from each level. I am expecting to write more cond clauses which will choose one branch (max node) over another. I want the recursive case to be a list that I can count...that's where I think I am stuck. Am I going about this the right way? Any suggestions much appreciated.