3
\$\begingroup\$
    1
   1 1
  1 2 1
 1 3 3 1

What do you think of this solution for computing Pascal's triangle?

(define (pascal row column)
  (cond ((or (= row column) (= 1 column)) 1)
        (else (+ (pascal (- row 1) (- column 1)) 
                 (pascal (- row 1) column)))))
\$\endgroup\$
3
\$\begingroup\$

You may use memoization to reduce your algorithm's complexity from O(2 ^ n) to O(n ^ 2).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.