Question: An empty tree is represented by null. A non - empty tree is represented by an object representing its root. The attribute x holds the
An empty tree is represented by null. A nonempty tree is represented by an object
representing its root. The attribute x holds the ID of the node, whereas attributes and r
hold the left and right subtree, respectively. For example, in the figure above, the tree is
rooted in node
Notice that the binary tree data structure is correct if and only if each node is a subtree
of exactly one other node, except for the root, which cannot be a subtree of any other
node.
Nodes X and Y are connected if node X points to node Y as its left or right subtree or if
node Y points to node X as its left or right subtree. For example, in the figure above:
nodes and are connected,
nodes and are connected,
nodes and are not connected.
The binary tree can be rerooted by changing its root to another node, which is a leaf. The
rerooted tree should maintain all the connections of the original tree if nodes X Y are
connected in the original tree then nodes X Y should remain connected in the rerooted
tree.
The order of subtrees in the rerooted tree is not significant. In other words, it is
permissible to swap the left and right subtree for each node.
For example, the figure below shows the tree from the previous example rerooted to
node
Test O
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
