Some useful algorithms to never forget
The first line contains an integer n, the number of nodes in the tree. Next line contains n space separated integer where ith integer denotes node[i].data.
Remember that in a binary search tree, all nodes on the left branch of a node are less than the node value, and all values on the right branch are greater than the node value.
The bfs function prints a single line with n integers denoting the node order in a bfs(breadth-first search) of the binary tree.
7
5 8 3 4 2 1 9
5 3 8 2 4 9 1