BFS and DFS implemented with their tests.