Java Implementation of BFS and DFS