Do level order traversal starting from root
q . append ( root ) NEW_LINE while ( len ( q ) > 0 ) : NEW_LINE INDENT node = q . pop ( 0 ) NEW_LINE if node . left is not None : NEW_LINE INDENT q . append ( node . left ) NEW_LINE DEDENT if node . right is not None : NEW_LINE INDENT q . append ( node . right ) NEW_LINE DEDENT node = None NEW_LINE DEDENT return node NEW_LINE