TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

"The worst algorithm in the world?"

161 点作者 mccutchen大约 14 年前

12 条评论

mynegation大约 14 年前
Very good demonstration of subsequent improvements of a naive algorithm. To me that was somewhat depreciated by the fact that you can actually calculate n-the Fibonacci number using Binet's closed form formula (<a href="http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_expression" rel="nofollow">http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_ex...</a>). You will need arbitrary precision arithmetic starting with certain 'n' though, as IEEE 754 will not give you correct result.
评论 #2538724 未加载
评论 #2538475 未加载
评论 #2538571 未加载
mccutchen大约 14 年前
The title is hyperbole (I'm sure that I've written much, much worse algorithms, many times), but the breakdown of Fibonacci sequence algorithms is really enjoyable.
评论 #2538823 未加载
perlgeek大约 14 年前
&#62; It’s not just bad in the way that Bubble sort is a bad sorting algorithm; it’s bad in the way that Bogosort is a bad sorting algorithm.<p>Nonono, Bogosort is way worse than naive recursive fibonacci - the former doesn't even guarantee termination, recursive fibonacci still does.<p>If you want to calculate fibonacci numbers not as a misguided exercise in algorithms but actually efficiently, use an algebraic form: <a href="http://en.wikipedia.org/wiki/Fibonacci_number#Computation_by_rounding" rel="nofollow">http://en.wikipedia.org/wiki/Fibonacci_number#Computation_by...</a>
评论 #2538587 未加载
qntm大约 14 年前
I always find it incredibly difficult to concentrate on comparisons of Fibonacci sequence algorithms when I know for a fact that there is a closed-form expression[1] which gives F(n) in constant time.<p>[1] <a href="http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_expression" rel="nofollow">http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_ex...</a>
评论 #2540109 未加载
_delirium大约 14 年前
In a somewhat similar genre, I enjoyed this paper on computing primes, and some of the very-inefficient algorithms that have been used for such purposes (often mislabeled as the "sieve of Eratosthenes"): <a href="http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf" rel="nofollow">http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf</a>
ubasu大约 14 年前
It seems the author hasn't read SICP:<p><a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.2" rel="nofollow">http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html...</a>
评论 #2538902 未加载
评论 #2538501 未加载
TheBoff大约 14 年前
Ppffftt, I wrote a recursive algorithm that calculates 2^n in O(2^n) time for an exam question.<p>That's what I call a bad algorithm!
mwbiz大约 14 年前
If you're writing in JavaScript it's a nice candidate for self memoizing functions. Obviously this is only helpful if you're making numerous requests to the method, a single request still produces a series of recursive calls.
评论 #2538683 未加载
michaelcampbell大约 14 年前
I always liked the sort where you randomize the elements, check to see if they're sorted, and if not try again.
评论 #2538335 未加载
评论 #2538155 未加载
评论 #2538619 未加载
samuel大约 14 年前
Dunno. IIRC Every time I have seen the "bad" Fibonacci recursive algorithm has been followed by the "good" recursive one (bottom-up), which is O(1) in size if your language/implementation does tail-call elimination...
georgieporgie大约 14 年前
This started out taking baby steps, then took a huge leap in complexity right here:<p><i>Since the Fibonacci numbers are defined by a linear recurrence, we can express the recurrence as a matrix, and it’s easy to verify that...</i><p>It's been way too long since my math minor for me to understand that.
评论 #2538612 未加载
ignifero大约 14 年前
Interesting writeup, thanks. OT: For all its fame, has any of you ever needed to calculate Fibbonacci numbers in real life? I haven't.
评论 #2538420 未加载
评论 #2538083 未加载