60.1k views
4 votes
For the Expression Tree corresponding to the following expression, what is the Height of the tree? [(x + 2) - 3] * [4 / (y * b + c)]

1 Answer

3 votes

Answer:

The height of the tree is 4

Step-by-step explanation:

First, we need to draw the tree

...........................(*)

.........(-)............................(/)

.....(+)........(3)----------.(4)..............(+)

(x).....(2)---------------------------(*)...............(c)

--------------------------------(y)..........(b)

To calculate the height; the height of a tree would be the height of its root node, or equivalently, the depth of its deepest node.

The root node is either the topmost or the bottom node in a tree data structure, depending on how the tree is represented visually.

Here, the root node is (*)

We start our calculation from the node at the opposite level of the root node which is (y) and (b)

We start our count from 0.

From (y) and (b) to the next linking node is (x), count = 1

From (*) to (+), count increases to 2

From (+) to (/) count increases to 3

Lastly, from (/) to (*), count increases to 4

So, the height of the tree is 4

User LostPixels
by
4.9k points