Elementary Algorithms in Java

This is a collection of elementary algorithms (lists, sorts, trees, etc..), written in Java. Most of these algorithms are written as Java generics (implementing the Comparable interface/class). They all include simple unit tests.

A number of these algorithms were written as solutions for problems in Cracking the Coding Interview: 150 Programming Questions and Solutions by Gayle Laakmann McDowell (2013). Even if you're a very experienced software engineer (which I am) I highly recommend Ms. McDowell's book. I should have read it much earlier than I did.

I was (or am, depending on when you read this) in graduate school, in the University of Washington's Computational Finance and Risk Management Masters program, while working full time from (June 2011 to December 2013).

Between work and school there was not much time to do anything else. However, near the end of grad school, in June 2013, during a ten day break between Quantitative Risk Management and Monte Carlo Methods in Finance, I wrote the code that is published here to practice for interviews.

Algorithms

With the exception of the String algorithms, all of the algorithms are generic. The generic file based merge sort code will sort serialized Java objects. This code might actually be useful, although it is probably already in one of the Java class repositories (e.g., Apache).

All of the major function have JUnit tests that go along with them.

When it comes to practicing for interviews, this didn't turn out to be that useful. I forget these algorithms a month or so after I write them.

Rather than spend time writing largely trivial algorithms (with the exception of merge sort), I'd rather spend my time writing software that I care about (for example, I'm working on a multi-threaded market order matching engine).

Code

You can download the code as a .tar file by clicking here.

Code and Documentation

You can browse the Doxygen formatted documentation and code here.

Ian Kaplan, June 2013
Last revised:


back to Java Topics