For this question, consider the following class which will be used to construct binary trees. Use the convention that there is no "empty tree"; each node points to the nodes containing it's two children; and if a node has no left or right child, then the corresponding pointer will be set to null
public class TreeNode {
public double root;
public TreeNode left;
public TreeNode right;
}
Draw a diagram for what a tree of this model would look like if the root node is pointed to by a TreeNode pointer called start; the root contains 3.0 and has no left child; its right child contains 2.5 and has no right child; and its left child is a leaf with value 8.13
Model Given -
Now we need to draw a diagram for a tree that has given -
1. root node is pointed by a TREENODE pointer Start.
2. for this start node (A) , we are give three values for node A - ROOT = 3.0 , LEFT = Null ,RIGHT = node B
3. we are give values for node B- ROOT = 2.5, LEFT = node C , RIGHT = Null
For the left child of node B , it is give that it is a leaf node(both child will be null ) with value 8.13. We will name this as node c. for node C- ROOT = 8.13, LEFT = Null , RIGHT = Null
So, above is the final diagram of the tree, according to the given in question.
Other representation -
Get Answers For Free
Most questions answered within 1 hours.