Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: fibonacci numbers using subroutine?

by FunkyMonk (Chancellor)
on Aug 20, 2010 at 00:13 UTC ( [id://856157]=note: print w/replies, xml ) Need Help??


in reply to fibonacci numbers using subroutine?

For extra points, check out what Wikipedia has to say about Fibonacci numbers, and then implement a recursive1 solution.

Recursion can lead to some wonderfully beautiful solutions to programming problems, but not always efficiently. Memoize can often increase their efficiency greatly, so take a look at that too.

Post your solutions here for further comment, and enjoy your journey.

Good luck

---
[1] 30 years ago, when I was a student, one of the researchers told me about quicksort. He told me that to sort a list, I should split it in to two lists, sort each list, and repeat. That was when I recognised the beauty of recursion.

  • Comment on Re: fibonacci numbers using subroutine?

Replies are listed 'Best First'.
Re^2: fibonacci numbers using subroutine?
by JavaFan (Canon) on Aug 20, 2010 at 13:09 UTC
    30 years ago, when I was a student, one of the researchers told me about quicksort. He told me that to sort a list, I should split it in to two lists, sort each list, and repeat. That was when I recognised the beauty of recursion.
    While quicksort splits the list into two, as you describe it, it sound more like merge sort. The essence of quicksort is that you partition the list using a pivot element.
    Recursion can lead to some wonderfully beautiful solutions to programming problems, but not always efficiently. Memoize can often increase their efficiency greatly, so take a look at that too.
    I'd say that if memoizing your recursive function speeds it up significantly, it's likely there's a more efficient iterative solution.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://856157]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found