Breadth First Search implemented in Python