Draw the Binary Tree that is constructed by calling the following methods.
BinaryTree T1;
T1.addRoot(5);
addLeft(T1.root(), 10);
addRight(T1.root(), 15);
BinaryTree T2;
T2.addRoot(20);
addLeft(T2.root(), 18);
addRight(T2.root(), 26);
BinaryTree T;
T.addRoot(8);
attach(T.root, T1, T2);
Upload an image showing the tree diagram or show it as following, make sure your result is clear enough to tell the left child or right child or parent node relation. Details regarding the used method can be found under content->others->binary tree code->linkedBinaryTree
1
2 3
5
Solution:
Tree is given below:
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Draw the Binary Tree that is constructed by calling the following methods. BinaryTree T1; T1.addRoot(5); addLeft(T1.root(),...
Add a non-recursive inorder() method to class LinkedBinaryTree<E> to traverse binary tree. Test inorder() method. Implementation in Java #########LinkedBinary Tree class######### public class LinkedBinaryTree<E> extends AbstractBinaryTree<E> { //---------------- nested Node class ---------------- /** Nested static class for a binary tree node. */ protected static class Node<E> implements Position<E> { private E element; // an element stored at this node private Node<E> parent; // a reference to the parent node (if any) private Node<E> left; // a reference to the left...
Complete HeapPriorityQueue (7 points). In lecture we implemented HeapPriorityQueue using an array-based representation of a heap (a complete binary tree whose entries satisfy the heap-order property). For this problem, complete the included HeapPriorityQueue class by using the LinkedBinaryTree class to represent a heap. Hint: the most challenging part of this problem is identifying the last Position in the heap and the next available Position in the heap. It is suggested that you review the array-based heap to better understand how...
This is in Java Create a client class that does the following: Manually creates an instance of a binary expression tree that represents the following expression: (((5+2)*(2-1)/((2+9))+((7-2)-1))*8) Do this by using methods such as addRoot, addLeft, addRight, set, and attach. The element should be of type String Note that you are manually building this specific expression tree, the pseudo code might look something like: Create a LinkedBinaryTree Add “*” as the root to the tree Add “/” as the left...
A binary tree is constructed of nodes that are instances of the following class: public class Node public int val public Node left public Node right) Consider the following method public static Node mystery Node root) rootghtanul return root else return mystery root ) You consult Professor Kennedy and hegves an opinion about what the method does when passed a reference to the root node of a binary tree. Assuming he is correct what does the mystery function do? it...
I need to do a tree sort method but the treesortMethod is not working /****Binarytree class****\ package Tree; public class BinaryTree { private TreeNode root; // head of the list //constructor - create an empty binary tree public BinaryTree() { root = null; } //isEmpty() - return true if tree is empty, false otherwise public boolean isEmpty() { return (root == null); } //deleteTree() - remove all items from tree public void deleteList() { root =...