Skip to content

Instantly share code, notes, and snippets.

@ravinggenius
Created January 21, 2015 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravinggenius/9a378376d237a31ad754 to your computer and use it in GitHub Desktop.
Save ravinggenius/9a378376d237a31ad754 to your computer and use it in GitHub Desktop.
linear recursion versus tree recursion
(define fibonacci
(lambda (n)
(if (< n 2)
1
(+ (fibonacci (- n 1))
(fibonacci (- n 2))))))
(define fibonacci
(lambda (n)
(define iter
(lambda (i n1 n2)
(if (= i 0)
n2
(iter (- i 1)
n2
(+ n1 n2)))))
(iter n 0 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment