Code

The Skip List

May 18, 2015 Code No comments

The skip list is my favorite data type. This may be because of some exposure to AVL trees back during my college days. Self balancing trees are wonderful, but they can be difficult to reason about.  If someone was to ask me what goes on when a value is inserted or deleted from an AVL tree, my answer would probably be “magic occurs”, and frankly, its magic I don’t care to dabble in.

Skip lists, on the other hand, are built on nice, classic linked lists. Linked lists get a bad rap when compared to List structures backed by an array, but they have their advantages. When comparing them to trees, it is important to realize that the trees are linked lists themselves.

(more…)

What goes on behind the scenes of += with String in Java

August 17, 2014 Code No comments ,

For some reason, the designers of Java decided to make + and += work with Strings. These are the only Objects in Java that have an overloaded operator that turns out to do some magic behind the scenes.

You see it all over the place:

But when is this acceptable when when is it problematic?
(more…)

Fun with dc(1) – counting zeros in factorials

June 3, 2014 Code No comments ,

Recently I stumbled across a question of “write a program to calculate the number of trailing zeros in n!” For example, 5! = 1 * 2 * 3 * 4 * 5 = 120. Thus, the number to get out of the program is 1. 10! is 3628800, and should get the result of 2.
(more…)