Created
April 6, 2011 01:06
-
-
Save arademaker/904929 to your computer and use it in GitHub Desktop.
Duas versões de Fibonacci apresentadas em sala (Mestrado EMAP/FGV). Exemplos do Livro Algorithms (http://books.google.com/books?id=3sCxQgAACAAJ).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib1(n): | |
if n == 0: | |
return 0 | |
if n == 1: | |
return 1 | |
else: | |
return fib1(n-1) + fib1(n-2) | |
def fib2(n): | |
if n == 0: | |
return 0 | |
nums = range(n+1) | |
nums[0] = 0 | |
nums[1] = 1 | |
for i in range(2,n+1): | |
nums[i] = nums[i-1] + nums[i-2] | |
return nums[n] | |
# Uso do modulo cProfile (aula 4) | |
def main(): | |
fib1(5) | |
import cProfile | |
cProfile.run('main()') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment