Programming and Webmasters forum
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

program for fibonnaci number in python

 
webmaster forum
raj  Offline
 
New Coder
Posts: 25
Topics: 14
January 25, 2009, 02:24:38 AM

I was trying to write a program for Fibonacci as is described on wikipedia and the problem that I am facing is that no matter how big I keep the limit it says to be overflowing.
I have tried keeping it unlimited but still the same problem arises.
 
webmaster forum
polas  Offline
*
 
Code Guru
Gender: Male
Posts: 1296
Topics: 80
WWW
January 25, 2009, 01:23:29 PM

Post the python code here, I don't know python but might be able to figure out what has gone wrong

Mesham Type Oriented Parallel Programming Language
 
webmaster forum
singam  Offline
 
Regular Coder
Posts: 50
Topics: 18
July 02, 2010, 08:31:08 PM

Although the recursive implementation given above is elegant and close to the mathematical definition, it is not very practical. Calculating the nth fibonacci number requires calculating two smaller fibonacci numbers, which in turn require two additional recursive calls each, and so on until all branches reach 1. The iterative solution is faster, but still repeats a lot of calculations when computing successive fibonacci numbers. To remedy this, we can employ memoization to cache previous computations.

We first establish a memoization "cache", which stores previously computed fibonacci numbers. In this case we use an ArrayList, initialized with the first two fibonacci numbers, as the cache. Note that we have also moved from using ints to using Java's BigInteger class, which provides arbitrary-precision integers. As a result, the memoized implementation can also compute much larger fibonacci numbers than the previous solutions (although they too could have been implemented using BigIntegers.
===============
Ben 10 Games


 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1221
Topics: 95
Technical_Talk
WWW
July 03, 2010, 07:08:02 AM

@singam: Thank you for the post.

Watch out for the latest Weekly Contests | Contest Rules
A Game - Say "Hello"
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC


Google visited last this page August 11, 2010, 10:40:48 PM