DFS and BFS traversal with ruby