[racket] I don't understand structural recursion.
On 17/09/11 23:04, Nadeem Abdul Hamid wrote:
> Do you have some examples? Concrete examples of possible input values
> and what you expect the corresponding output to look like? And if the
> function expects integers as input, then what is the difference in the
> output between two successive input values like 2 and 3? 4 and 5? 0
> and 1?
I forgot to mention, I believe the difference between success node
values corresponds to the Catalan numbers. I'm not certain of this, I
just have a function that I believe outputs the number of distinct
sequences, which the OEIS claimed was the Catalan sequence
(http://en.wikipedia.org/wiki/Catalan_number)
(define (num-distinct-btrees N)
(if (<= N 1)
1
(accumulate
(λ (Np)
(* (num-distinct-btrees (- Np 1))
(num-distinct-btrees (- N Np))))
(build-list N add1))))
(define (accumulate f list)
(if (empty? list)
0
(+ (f (car list))
(accumulate f (cdr list)))))
Damien.