- #1
lyd123
- 13
- 0
The question asks you to balance a syntax tree. The first part is to describe the tree transformations needed to make it a complete tree. I've attached an example of the transformation.
We will know its a compete tree if (heightOfShortestSubTree -heightOfTallestSubTree<=1).
Normal transformations of BSTs which I know of, won't be fully right because those try to keep the order of numbers correct i.e smaller numbers on the left, bigger on the right. But in this question, order of numbers doesn't matter, except if the operator is a minus. If a node has a 'minus', then that sub-tree's structure can't be changed, because subtraction isn't associative or commutative. How would I approach this question? Thank you!
View attachment 8739
We will know its a compete tree if (heightOfShortestSubTree -heightOfTallestSubTree<=1).
Normal transformations of BSTs which I know of, won't be fully right because those try to keep the order of numbers correct i.e smaller numbers on the left, bigger on the right. But in this question, order of numbers doesn't matter, except if the operator is a minus. If a node has a 'minus', then that sub-tree's structure can't be changed, because subtraction isn't associative or commutative. How would I approach this question? Thank you!
View attachment 8739