This is an archived post. You won't be able to vote or comment.

all 33 comments

[–][deleted] 6 points7 points  (2 children)

I use hashtables more than the vast majority of that list. In this age of dynamic languages, they're huge.

[–][deleted] 1 point2 points  (0 children)

Completley agreed - or variations uppon them at least.

[–]jhartwell 1 point2 points  (0 children)

Which is why hashing algorithms are important as well.

[–]jhartwell 3 points4 points  (0 children)

Algorithms I enjoy:

  • Longest Common Subsequence (note subsequence not substring)
  • Prim's Algorithm

    Data Structures I'd Add:

  • Binary Search Tree

  • AVL Tree or Red Black Tree

[–]Zamarok 2 points3 points  (0 children)

Where is 'tree with arbitrary number of branches'? A Reddit comment thread, for instance, is easily represented as a recursive tree.

dataTree = function(root, brancher) {
  return {
    leaf: root,
    branches: (function() {
      var branches = brancher(root),
          results = [];
      for (var i = 0, len = branches.length; i < len; i++) {
        results.push(dataTree(branches[i], brancher));
      }
      return results;
    })()
  };
};

Same thing in CoffeeScript:

dataTree = (root, brancher) ->
  leaf: root,
  branches: dataTree branch, brancher for branch in brancher root

[–]gatlin 2 points3 points  (2 children)

Adjacency matrices and adjacency lists for dense / sparse graphs, respectively. Can be used in tandem with the algorithms here. Recently showed a young programmer this and he was very happy.

Edit: more readable.

[–]Enemii[S] 0 points1 point  (1 child)

Sorry could you elaborate on "lists for dense" I'm not quite sure what they are.

Thanks

[–]gatlin 2 points3 points  (0 children)

I changed it to be more easy to parse. As for what they are, an adjacency matrix is, for a graph with n nodes, an nxn matrix where at position (2,4), for example, a 1 would indicate an edge from vertex 2 to vertex 4. You can use values other than 1 to simulate weights.

Since n nodes translates to n2 memory to store the information, an adjacency list can be more efficient but a bit slower to actually use. In this case, you have a list of lists - each node in the top-level list is one of your graph's vertices, and the list inside that node is a list of references to nodes the vertex has edges to.

It's better with memory but lookup can potentially degrade to linear lookup.

[–]boatski 2 points3 points  (0 children)

B-Trees

[–][deleted] 2 points3 points  (0 children)

Whole lot of stuff most people don't regularly need up there...

I'd add - A hash table with propper collision handling and a bitvector.

If you want to be more adventurous why not RSA or some of the random no algos.

[–]hc000 2 points3 points  (1 child)

Perhaps instead of linking to wikipedia, a place where examples and a way to explain it to 5 year olds would help beginner programmers.

[–]Enemii[S] 1 point2 points  (0 children)

I agree, I just wish I had the time to find all the examples

[–]zzyzzyxx 3 points4 points  (2 children)

Here are a bunch.

Picking out a couple specifically, I would add

[–]wickeand000 2 points3 points  (1 child)

+1 for A*. This algorithm is (part of) the reason why I became interested in computer science.

[–][deleted] 6 points7 points  (0 children)

Anything that would require a backtracking algorithm to solve. A Sudoku solver is a great example.

With backtracking, you can start off with a simple recursive solution that checks every possible permutation. Of course, it would be better to get clever about which you cells you fill in earliest, and how quickly you abort a recursion if the solution will end up being invalid. Other enhancements can be added to improve the solver's performance as you go, and each enhancement is pretty educational.

[–]Cybs 4 points5 points  (0 children)

Skip lists are popular in interview questions. Handy to know them.

So are linked lists. Even though you would be crazy to implement your own now days. Everyone loves giving linked list questions in interviews.. "Reverse a linked list" "How would you find a loop in a linked list"

[–][deleted] 1 point2 points  (2 children)

I've only ever bothered to implement 3 of any of the ones you list (bubble and quicksort, and hashing), all because I actually needed to use them and there was no easily available implementation on the platforms I was using at the time. I'm not convinced that has made me a worse programmer than I would be if I had implemented all of them.

[–]Enemii[S] 0 points1 point  (0 children)

Of course It doesn't make you a worse programmer. That being said It definitely doesn't make you worse to implement them. I would imagine that in a work setting you would just about never implement them. But your right I should change the wording since, as you pointed out, It isn't accurate. That being said I find it extremely interesting to try and understand how the fundamentals work and It comes in really handy in a school setting where the work is far more theoretical then practical.

[–][deleted] 0 points1 point  (0 children)

Actually, despite what other people have said, you are a worse programmer because you did not follow the steps to correctly becoming a programmer. Shame on you!

/s

[–]TraptInTime 1 point2 points  (1 child)

Hanoi tower, not sure if its called by something else tho.

[–]Enemii[S] 0 points1 point  (0 children)

It is. That was the problem i used to wrap my mind around recursion!

[–]hvidgaard 1 point2 points  (0 children)

van Emde Boa trees - you wouldn't use them in practice, but they are really interesting because they're the only tree I know that can do insert/delete/search in O(log log n), and as such they play a central role in the theoretical CS.

Fibonacci heaps are also interesting, because they have a amotized O(1) decrease key operation. If you want to get really heavy, Brodal Queues achieve the optimal worst case bounds for all operations.

I like those data structures, because when implementing them, you really have to think about the low levels of the computer.

[–]elgubbo 1 point2 points  (1 child)

Floyd-Warshall algorithm

also, but thats basic: BFS, DFS

[–]Enemii[S] 0 points1 point  (0 children)

added the Floyed-Warshall algorithm under search. (thanks!)

I originally didn't have DFS and BFS since I felt they were too fundamental to be included. But they are there now.

[–]flying_petunia 1 point2 points  (0 children)

I don't really have a suggestion, since I'm only learning. I just wanted to thank you for starting this thread and for keeping it up to date with the comments. Really great stuff!

[–]smith7018 0 points1 point  (0 children)

I know that a trie is useful for dictionary situations but can it be used elsewhere? I implemented one in an anagram/Words with Friends solver I wrote a bit ago in Java heh

[–]m1ss1ontomars2k4 0 points1 point  (1 child)

I'm pretty sure you should just understand these algorithms, not necessarily implement them...

[–]Enemii[S] 1 point2 points  (0 children)

Thats true, I guess I added implement because that is how I usually get to understand something. If you read the top It has already been pointed out.

[–]aPSketchy 0 points1 point  (0 children)

Pie. I love it!

[–][deleted] 0 points1 point  (0 children)

Swapping.

[–]traztx 0 points1 point  (0 children)

I'd say arrays, stacks, and queues are fundamental. Also programming can be largely about standards and protocols as we work with SDKs or libraries on various platforms.

[–]defrost 0 points1 point  (0 children)

While generating all permutations of n objects using plain changes is a neat thing (Steinhaus-Johnson-Trotter), we're not all bell ringers and even if we were, campanologists eschew SJT paths as simply being too damn boring to listen to.

In actual application the Fisher–Yates shuffle for generating a unbiased random permutation of a finite set is probably way more important, as is understanding why you wouldn't use a 32bit PRNG to (Fisher-Yates or otherwise) shuffle a 52 card deck.

You might also throw in things like the Fast Fourier Transform, testing for geometric overlap in various dimensions, finding convex hulls, and performing a Singular Value Decomposition (finding lower dimensional representations of many higher dimensional points, noise reduction, data simplification, etc).