Question

For this question, consider the following class which will be used to construct binary trees. Use...

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

Homework Answers

Answer #1

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 -

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class....
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class. Make every Node object have a false isBlack field, all new node is red by default. In the end of the insert method, set the root node of your red black tree to be black. Implement the rotate() and recolor() functions, and create tests for them in a separate class. import java.util.LinkedList; public class BinarySearchTree<T extends Comparable<T>> { protected static class Node<T> { public...
In heapsort we view an array as a binary tree using the following mapping: a[0] is...
In heapsort we view an array as a binary tree using the following mapping: a[0] is the root of the entire tree and for element a[i], its left child is a[2i+1] and its right child is a[2i+2]. Answer the following questions for an array of size n. ( Answers in some cases may be in terms of n.) a) What is the index of the parent a[i] for any i > 0? b) What is the biggest index for which...
Binary Heap with root index of 1 (a) If a node is at index k ,...
Binary Heap with root index of 1 (a) If a node is at index k , what is its parent’s index? b) If a node is at index k , what is its left child index? c) If a node is at index k , what is its right child’s index? d) What is the largest index of a node has at least a child in a heap with n nodes?
I have written working code for this problem however it is not producing an output and...
I have written working code for this problem however it is not producing an output and it states is a wrong answer. Please just fix my code below and make it work for the sample test cases and all test cases. You are given a pointer to the root of a binary search tree and values to be inserted into the tree. Insert the values into their appropriate position in the binary search tree and return the root of the...
The Binary Search Tree implementation for bst.zip. The code in the destructor of the BST class...
The Binary Search Tree implementation for bst.zip. The code in the destructor of the BST class is empty. Complete the destructor so the memory allocated for each node in the BST is freed. Make a couple of different trees in your main method or in a function to test the destructor (the program should not crash upon exiting). bst.zip (includes the following files below in c++): bst.h: #pragma once #include #include "node.cpp" using namespace std; template class BST { public:...
Input: A binary tree T in which each node x contains a field worth[x], which is...
Input: A binary tree T in which each node x contains a field worth[x], which is a (positive, zero, or negative) monetary value expressed as a real number. Define (monetary) heritage of a node x to be the total worth of ancestors of x minus the total worth of proper descendants of x. Output: A node x in T with maximum heritage. Note: other than the field worth and left/right child pointers, nodes of the given tree do not have...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the in-order traversal as the default.             This means, in Tester the following code should work for an instance of this class             called bst that is storing Student objects for the data:                 BinarySearchTree_Lab08<String> bst = new BinarySearchTree_Lab08<String>();                 bst.add("Man");       bst.add("Soda");   bst.add("Flag");                 bst.add("Home");   bst.add("Today");   bst.add("Jack");                ...
Design a recursive algorithm with proofs of the following: Richest Heritage: Input: A binary tree T...
Design a recursive algorithm with proofs of the following: Richest Heritage: Input: A binary tree T in which each node x contains a field worth[x], which is a (positive, zero, or negative) monetary value expressed as a real number. Define (monetary) heritageof a node x to be the total worth of ancestors of x minus the total worth of proper descendants of x. Output: A node x in T with maximum heritage Note: other than the field worthand left/right child...
Copy the file SimplerBST.java from the week 1 examples package and rename the file and class...
Copy the file SimplerBST.java from the week 1 examples package and rename the file and class A3BST. Add two public methods: one named countTwins that takes no parameters and that, when called, traverses every node of the tree to count the number of nodes having two children. one named lessThanValueCount that takes a paremeter of generic type V, and that, when called, traverses every node of the tree to count the number of nodes whose value (not its key) is...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT