i have an array of the pre order traversal
and i know that the root it arr[0]
and its left son is arr[1]
whats the formula for spotting the value of its right son value
??
i have an array of the pre order traversal
and i know that the root it arr[0]
and its left son is arr[1]
whats the formula for spotting the value of its right son value
??
Given, node with index i and it's left child is 2i. Working out what the right child is shouldn't be too hard for you.
Hint: Draw the tree and its array.
its not 2i but i+1
i got to that conclution too
but the right son is hard
because if a tree is not simetric and somewhere we dont have a left of right node
then we cant break it into two
i think the answer is searching the first node whoch is larger then arr[i]
is it ok?
Just use a value that wasn't in the tree before you flattened it as nil.