I am working on a small algorithm that builds a binary tree in level order. I have been given an array, and I have to use the values in it to build the binary tree in level order. Example: arr inarr [5] = {1,2,3,4,5};
for such an array, I need to populate the binary tree so that it looks like this:
1
/ \
2 3
/ \ / \
4 5 * *
(* - NULL) nodes are the basic binary nodes with left and right pointer and space for an int that contains a value from an array.
I understand the concept of passing a tree along its height, and you move through it one level at a time, but I'm not sure of the correct logic that will correctly construct it in this way.
source
share