TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What is your favourite algorithm?

16 pointsby redxbloodover 11 years ago

13 comments

blubbi2over 11 years ago
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 未加载
Rickasaurusover 11 years ago
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>
cpncrunchover 11 years ago
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 未加载
lsiebertover 11 years ago
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.
mistabrandoover 11 years ago
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
andrewhillmanover 11 years ago
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.
juntoover 11 years ago
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-gover 11 years ago
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>
LarryMade2over 11 years ago
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...
sharemywinover 11 years ago
Restricted Boltzmann Machine
tbirdzover 11 years ago
It&#x27;s more of a method than an algorithm, but I&#x27;m a big fan of Dynamic Programming.
WasimBhaiover 11 years ago
Viterbi. Beauty.
helpermethodover 11 years ago
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.