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)))))
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Mar 25, 2011 at 2:33
\$\endgroup\$
0

1 Answer 1

4
\$\begingroup\$

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

answered Mar 25, 2011 at 9:52
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.