Depth First Search and Breadth First Search in Python