breadth first search source code in python code example
Example: python breadth first search
# tree level-by-level traversal. O(n) time/space
def breadthFirstSearch(root):
q = [root]
while q:
current = q.pop(0)
print(current)
if current.left is not None: q.append(current.left)
if current.right is not None: q.append(current.right)