Google Interview Question

Print a BST level by level

Interview Answers

Anonymous

Sep 5, 2017

This is just a BFS of the tree

Anonymous

Sep 27, 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)