What Are The Top 10 Algorithms Every Software Engineer Should Know by Heart?
What Are The Top 10 Algorithms Every Software Engineer Should Know by Heart?
What Are The Top 10 Algorithms Every Software Engineer Should Know by Heart?
That being said, here are a couple of the (less than 10) algorithms that I DO know by
heart, because they're pretty fundamental:
Joe Zbiciak
7 upvotes Upvoted by Gideon Shavit, Professional Software Engineer for 25
years
Caching can happen at multiple levels, too. If you program in a more functional direction, with side-
effect-free/pure functionsthat is, you have referential transparencyyou can trivially cache those
functions results. Doing this at the function level is sometimes called memoization.
For certain classes of algorithm, it can turn deep searches into shallow lookups. Ive found it
tremendously useful over the years. Im also surprised how many people are unaware of the technique.
Note: When I say program in a more functional direction, I dont mean program in Haskell or
Scala. I just mean avoid side-effects and mutable state wherever possible. I wrote a fairly complex
constraint solver in C++ a couple years ago, and I stuck to a everythings const once created
paradigm thats popular in functional programming languages. That allowed me to apply a few tricks:
(1) I could replace a given object with an integer index into a table of objects of that type. Since each
object captured a particular portion of the constraint solution computation, and the same intermediate
values get created again and again, compressing this to a single instance saves a lot of space. (Similar
to the Flyweight design pattern.)
(2) Since new objects were created by combining existing objects with various operators, and that
operation was side-effect free, I could easily memoize these computations. And since I had associated
all the unique objects with integers, I could look up the memod result in a hash table very quickly.
(3) Since all the various objects were remembered, I could always backtrack on a partial solution by
just remembering what set of objects I had at each step. Doing so was cheap since everything was
already captured in the unique objects table that mapped objects to integers.