Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'algorithm': 0.04; 'elif': 0.05; '*not*': 0.07; 'practice,': 0.07; 'subject:missing': 0.07; 'def': 0.12; 'wrote': 0.14; '24,': 0.16; '465': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'question': 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'is?': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'subject:what': 0.31; 'could': 0.34; 'but': 0.35; 'version': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'charset:windows-1252': 0.65; 'series': 0.66; 'mar': 0.68; 'received:74.208': 0.68; '2015': 0.84; 'received:74.208.4.194': 0.84; 'toy': 0.84; 'fibonacci': 0.91; 'inefficient': 0.91 Date: Mon, 23 Mar 2015 20:42:07 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: fibonacci series what Iam is missing ? References: <5510ad7a$0$12979$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <5510ad7a$0$12979$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:1uIqCZcPa0i3TAwKgLFiFnofu262fsjfNGpDu9qhs2T8Ps78CkC I2fIfJHAVBGUaBu9XnyHnfhlnd3zGQG7vtJkjtjYrN2rvID+mFL0+DdJogaTY+7ibiMi17v tuf8YycO9fBVmwFG4/b2PHNnNyc85IxqgbYXSdituArLCrkkJ29IJ6DXVyAIbCVzICG8uAK HIav1cKtbCnHYYO+oUYsw== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427157732 news.xs4all.nl 2940 [2001:888:2000:d::a6]:58195 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87857 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 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