Ruby Graph Traversal Algorithms