Coding up the BFS algorithm | O(V+E)