r/compsci • u/TopcatTomki • Aug 14 '13
Algorithims Everyone Should Know?
What are some of you're favourite algoritms or concepts that you think everyone should know, whether they solve problems that crop up frequently, or are just beautiful in their construction?
375
Upvotes
416
u/blexim Aug 14 '13 edited Aug 14 '13
Here's a random selection, approximately ordered from most basic to more advanced. I may add more later...
Edit: this is definitely not meant to be an exhaustive list, it's just a random selection of things I use a lot/think are cool.
Numerical:
Data structures:
Sorting & searching arrays:
Tree search:
Graphs:
Automata and parsing:
Numerical optimization:
Combinatorial optimization:
Graphics:
Compilers:
Machine learning:
Cryptography:
Miscellaneous:
Edit: Thanks for the gold!
14
u/cavedave Aug 14 '13 edited Aug 14 '13
Fair division procedures for problem solving reasons
*edit add Toilet Paper Algorithms
23
u/The_Double Aug 14 '13
Why does every algorithm discussion end up being about sorting?
Personally, I like the Trie, It's simple to make, but still really smart. And the name is nice too.
7
u/atomcrusher Aug 14 '13
At a basic level, I think everyone should go and learn basic sorting algorithms. Not necessarily being able to write them with your eyes closed or anything, but at least knowing how they work. It'll give them a basic knowledge of algorithm types (divide-and-conquer for QuickSort for example) and why some algorithms are better than others.
Edit: Basic.
6
u/tanglebones Aug 14 '13
A few more fun areas to explore:
3
u/costheta Aug 15 '13
Adding on to the existing comments:
Algorithms for voting systems:
Matching algorithms:
5
u/noodlefrenzy Aug 15 '13
Wow, I can't compete with blexim so I won't even try, but I'd also mention a few from distributed systems:
Oh, and I agree with everyone on Tries, they are super-useful.
(I'm sure more will come to me as soon as I hit save)
8
u/polyguo Aug 14 '13
Universal AI :
7
u/monochr Aug 14 '13
Not an algorithm, but one of the most useful tricks I've ever picked up:
Swapping between two integers without storing a value in a third:
It doesn't matter if the addition causes an overflow, the underflow from the subtraction cancels it.
2
u/[deleted] Aug 15 '13
I love graph dominator trees. And it's über surprising that nobody has yet mentioned topological sort.
Also, fingertrees.
3
u/Techmeology Aug 14 '13
Alpha-beta pruning: http://en.wikipedia.org/wiki/Alpha_beta_pruning
I think the compiler's section could also use a few extras, particularly the recursive decent parser.
3
u/[deleted] Aug 14 '13
Perhaps I'm alone here, but KNN has proved itself useful for me in the areas I've worked more than virtually anything else over the years.
Virtually any time you need to do some data interpolation about an unknown point given some known points around it, you're probably going to need KNN to determine the nearby known points that you actually care about.
2
u/JesusWantsYouToKnow Aug 14 '13
Path finding algorithms. Has obvious uses in AI and games, but a myriad of other nontrivial uses and will expose the uninitiated to graphs.
2
u/samrmc Aug 14 '13 edited Aug 14 '13
Binary searches are very useful for a lot of problems that are not necessarily related to computers. It's something that's not very complicated either, just divide and conquer. Related
1
u/Ok-Ingenuity-5990 Oct 25 '23
tournament style thinking as a general system for picking between multiple valid good choices is a beneficial idea, I believe. Just as in machine learning there may be multiple local maximums or minimums and you may not know which option to choose. Entering them in a competition against each other may be useful in those scenarios.
1
u/PasswordIsntHAMSTER Aug 14 '13
Rod cutting, all day everyday
0
u/costheta Aug 15 '13
Adding on to the existing comments:
Algorithms for voting systems:
Matching algorithms:
0
u/costheta Aug 15 '13
Adding on to the existing comments:
Algorithms for voting systems:
Matching algorithms:
-1
u/FearMonstro Aug 15 '13
http://www.cs.uvm.edu/~icdm/algorithms/10Algorithms-08.pdf
-4
u/[deleted] Aug 14 '13
Google remembers most algorithms for me.
0
u/simplyderp Aug 15 '13
A* search
0
u/[deleted] Aug 14 '13
[deleted] — view deleted comment