Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87857
| Date | 2015-03-23 20:42 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: fibonacci series what Iam is missing ? |
| References | <CACT3xuVF-MOVQK5wSorRSAfpAQEXvS7QsqarACVZKXsQ0bxzpQ@mail.gmail.com> <mailman.72.1427127417.10327.python-list@python.org> <5510ad7a$0$12979$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.89.1427157732.10327.python-list@python.org> (permalink) |
On 03/23/2015 08:19 PM, Steven D'Aprano wrote: > On Tue, 24 Mar 2015 03:16 am, Chris Angelico wrote about the standard > recursive version of the Fibonacci series: > >> On Tue, Mar 24, 2015 at 3:01 AM, Ganesh Pal <ganesh1pal@gmail.com> wrote: > >>> def fib(n): >>> if n == 0: >>> return 0 >>> elif n == 1: >>> return 1 >>> else: >>> return fib(n-1) + fib(n-2) > > >> 2) Your algorithm is about as hopelessly inefficient as it could >> possibly be, barring deliberate intent. > > > It is pretty inefficient, but it is a good toy example of recursion. It's > also a good example of how *not* to write the Fibonacci series in practice, > what is mathematically straightforward is not always computationally > efficient. > > The question is, just how inefficient is is? How many calls to `fib` are > made in calling fib(n)? > > Answer to follow. > > > 0 1 1 1 2 3 3 5 4 9 5 15 6 25 7 41 8 67 9 109 10 177 11 287 12 465 13 753 14 1219 -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: fibonacci series what Iam is missing ? Chris Angelico <rosuav@gmail.com> - 2015-03-24 03:16 +1100
Re: fibonacci series what Iam is missing ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-24 11:19 +1100
Re: fibonacci series what Iam is missing ? Dave Angel <davea@davea.name> - 2015-03-23 20:42 -0400
Re: fibonacci series what Iam is missing ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-24 11:56 +1100
Re: fibonacci series what Iam is missing ? Chris Angelico <rosuav@gmail.com> - 2015-03-24 11:59 +1100
Re: fibonacci series what Iam is missing ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-24 12:52 +1100
Re: fibonacci series what Iam is missing ? Rustom Mody <rustompmody@gmail.com> - 2015-03-23 19:23 -0700
Re: fibonacci series what Iam is missing ? Chris Angelico <rosuav@gmail.com> - 2015-03-24 14:03 +1100
Re: fibonacci series what Iam is missing ? Rustom Mody <rustompmody@gmail.com> - 2015-03-23 20:30 -0700
Re: fibonacci series what Iam is missing ? Rustom Mody <rustompmody@gmail.com> - 2015-03-23 21:13 -0700
csiph-web