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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: What is your favourite algorithm?

16 点作者 redxblood超过 11 年前

13 条评论

blubbi2超过 11 年前
Dijkstra&#x27;s algorithm ( <a href="http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Dijkstra%27s_algorithm</a> )<p>It is a really elegant algorithm and addresses a real-world problem. A teacher of mine once showed us the basic idea behind it:<p>He connected various bits of wood (=nodes) using strings (=edges). Then he picked up one bit of wood (=starting node) and slowly moved it upwards. Every time when a new node moves, it is an indication that the shortest path between the start node and the new node has been found. He did this until he reached the desired end node. The shortest path between the two nodes is in the end clearly visible, because the path between two nodes A and B that are part of the path between the start and end node is always the shortest path possible.<p>It is really simple if you think of it as a physical model, unfortunately I could not find a picture of it online :(
评论 #6352048 未加载
Rickasaurus超过 11 年前
Gale–Shapley algorithm (for the stable marriages problem) <a href="http://en.wikipedia.org/wiki/Stable_marriage_problem" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stable_marriage_problem</a><p>It&#x27;s a beautifully simple algorithm with uses in almost every field.<p>Here&#x27;s a more informative link <a href="http://cse331.wordpress.com/2009/09/11/lect-4-gale-shapley-algorithm/" rel="nofollow">http:&#x2F;&#x2F;cse331.wordpress.com&#x2F;2009&#x2F;09&#x2F;11&#x2F;lect-4-gale-shapley-a...</a>
cpncrunch超过 11 年前
My favourite would have to be one that I invented myself. I guess like a lot of people here I occasionally end up having to figure out algorithms to solve particular problems. That is one of the most rewarding aspects of being a programmer.
评论 #6344433 未加载
评论 #6342463 未加载
lsiebert超过 11 年前
I don&#x27;t know that I have favorites. That said, Radix sort is kinda cool. It&#x27;s O(n * k), where k is the number of digits in the number, but it&#x27;s possible to have k be a constant if there is a limit (like an int can only be so big) meaning you can have an O(n) sort.
mistabrando超过 11 年前
Sleepsort of course<p>#!&#x2F;bin&#x2F;bash<p>function f() {<p><pre><code> sleep &quot;$1&quot; echo &quot;$1&quot;</code></pre> }<p>while [ -n &quot;$1&quot; ]<p>do<p><pre><code> f &quot;$1&quot; &amp; shift </code></pre> done<p>wait
andrewhillman超过 11 年前
I really dig AI algorithms like...<p><a href="http://www.norvig.com/spell-correct.html" rel="nofollow">http:&#x2F;&#x2F;www.norvig.com&#x2F;spell-correct.html</a><p>Simplicity is beautiful.
junto超过 11 年前
I like the Monte Carlo algorithm: <a href="http://en.wikipedia.org/wiki/Monte_Carlo_algorithm" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Monte_Carlo_algorithm</a>
alok-g超过 11 年前
Chart parser, <a href="http://en.wikipedia.org/wiki/Chart_parser" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Chart_parser</a>
LarryMade2超过 11 年前
LSL LSR PHA PLA BYT BYT BYT<p>Shift to the left, Shift to the right, Push-a, Pull-a Byte, Byte, Byte!<p>Sorry, I just couldn&#x27;t resist...
sharemywin超过 11 年前
Restricted Boltzmann Machine
tbirdz超过 11 年前
It&#x27;s more of a method than an algorithm, but I&#x27;m a big fan of Dynamic Programming.
WasimBhai超过 11 年前
Viterbi. Beauty.
helpermethod超过 11 年前
Insertion sort. Easy to implement (easier than BubbleSort), very fast for small data sets. Can be used in merge sorts &#x2F; quick sorts when the set size becomes small.