News for hackers. Stuff that matters.
Re:Data structures and algorithms I actually used while work... by pps43 on Wednesday July 15, 2020 @09:17AM (#23844739)
> more elegant and simpler

Beauty is in the eye of the beholder, but a loop is hard to beat as far as simplicity goes, and you don't depend on your compiler being clever enough to optimize tail recursion.

If you need to traverse a tree then sure, but with Fibonacci you don't even need the stack to begin with. You only need to keep a previous number.

Re:Data structures and algorithms I actually used while work... by duskwuff on Wednesday July 15, 2020 @07:06PM (#23853491)
You don't even need a loop. Binet's formula gives a closed-form expression for the Fibonacci sequence. (And of course I don't remember that formula off the top of my head, but I know it exists, so I'd be 90% of the way to solving a problem which required it.)
Re:Data structures and algorithms I actually used while work... by pps43 on Wednesday July 15, 2020 @09:37PM (#23854775)
This will open another can of worms (floating point errors).