Google interview question

Print a BST level by level

Interview Answers

Anonymous

5 Sept 2017

This is just a BFS of the tree

Anonymous

27 Sept 2017

This is known as a Level Order Traversal, more or less just a typical BFS. Here's a Python implementation: def level_order(root): q = [root] while q: cur = q.pop(0) print(cur.data) if (cur.left): q.append(cur.left) if (cur.right): q.append(cur.right)