Ruby implementation of some graph algorithms