Skip to content

QuestionAnswered step-by-stepEleventh Assignment – Binary Se

Do you have a similar question? Our professional writers have done a similar paper in past. Give Us your instructions and wait for a professional assignment!        

QuestionAnswered step-by-stepEleventh Assignment – Binary Search Tree?ackage: edu.institution.asn11Class: BSTImplement a solution for problems 25.1. And 25.3 on page 960 of your textbook. Download theBST.zip file from the course website. BST.zip contains the BST.java class and the TreeNode classthat is presented in the book.?ou are required to implement the breadthFirstTraversal, height, and non-recursive inordertraversal methods described in Problems 25.1 and 25.3.?roblem 25.1 – BST Methods?he problem statement taken from the book:Add the following new methods in to the BST.java class.?**? Traverses the nodes using the breadth-first traversal algorithm and? and returns a list of elements in the correct order.? @return the elements in the order that reflects a breadth-first traversal.?/public List breadthFirstTraversal() {}/**? Returns the number of edges between the tree’s root and its furthest leaf.? @return the height.?/public int getHeight() {}??opyright ?2020. Doug Estep – All rights reserved.?opyright registration number: TXU002159309.1?he height of a tree is defined as the maximum the number of connections (also known asedges) from the root of the tree to the bottom. In the below tree, the height is three becausethe maximum number of connections (edges) from the root (George) to the bottom (Peter) isthree.?????George???/??????- edge 1?dam?????Michael???????/?????<- edge 2??Daniel???ones???Tom???????????/??- edge 3???????????eter?????Problem 25.3 - Inorder Traversal?he problem statement taken from the book:Re-implement the inorder method in a new method called, nonRecursiveInorder, in the BST.javaclass using a stack instead of recursion.?/**? Returns the results of an in-order traversal without the use of recursion.? @return the elements in the order that reflects an in-order traversal.?/?ublic List nonRecursiveInorder() {}??nit Tests?reate a JUnit test class to test the operation of your methods for trees containing twodifferent data types. Be sure to write enough tests to ensure all use cases work as specified.?Copyright ?2020. Doug Estep – All rights reserved.?opyright registration number: TXU002159309.2?ow You Are Graded?1. The breadthFirstTraversal method is correctly implemented (3 points)?. The getHeight method is correctly implemented (3 points)?. The nonRecursiveInorder traversal method is correct and has been re-implemented suchthat it doesn’t use recursion (3 points)?. You have written enough JUnit tests to validate these methods function as designed. (1point)?Notes?. Your project is sent to a service which tests and attempts to grade your assignment.That automated grading process is much easier if you follow the instructions with?egards to class names, method names, and output messages. I do evaluate your project?fter the automated grading occurs to help you understand any mistakes that waspointed out and possibly adjust any points that was deducted from your project.?. Your project is sent to a service that checks for plagiarism. If the service flags yourproject for plagiarism, I evaluate it against the student it matched to. If I determine thatyour project was plagiarized, you will receive a score of zero on the assignment.Continued offenses could result in disciplinary actions taken by this institution.?. If your program does not compile, you will receive a score of zero on the assignment4. If your program compiles but does not run, you will receive a score of zero on theassignment.5. If your Eclipse project is not exported and uploaded to the drop box correctly, you willreceive a score of zero on the assignment.6. If you do not submit code that solves the problem for this assignment, you will notreceive any points for the program’s compiling or the program’s running.?Copyright ?2020. Doug Estep – All rights reserved.?opyright registration number: TXU002159309.3?////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////BST.javaimport java.util.ArrayList;import java.util.Iterator;public class BST> { protected TreeNode root; protected int size = 0; public BST() { } public BST(E[] objects) { for (int i=0; i current = root; while (current != null) { if (e.compareTo(current.element) < 0) { current = current.left; } else if (e.compareTo(current.element) > 0) { current = current.right; } else { return true; } } return false; } public boolean insert(E e) { if (root == null) { root = createNewNode(e); } else { TreeNode parent = null; TreeNode current = root; while (current != null) { if (e.compareTo(current.element) < 0) { parent = current; current = current.left; } else if (e.compareTo(current.element) > 0) { parent = current; current = current.right; } else { return false; } } if (e.compareTo(parent.element) < 0) { parent.left = createNewNode(e); } else { parent.right = createNewNode(e); } } size++; return true; } protected TreeNode createNewNode(E e) { return new TreeNode(e); } public void inorder() { inorder(root); } protected void inorder(TreeNode root) { if (root == null) return; inorder(root.left); System.out.print(root.element + ” “); inorder(root.right); } public void postorder() { postorder(root); } protected void postorder(TreeNode root) { if (root == null) return; postorder(root.left); postorder(root.right); System.out.print(root.element + ” “); } public void preorder() { preorder(root); } protected void preorder(TreeNode root) { if (root == null) return; System.out.print(root.element + ” “); preorder(root.left); preorder(root.right); } public int getSize() { return size; } public TreeNode getRoot() { return root; } public ArrayList> path(E e) { ArrayList> list = new ArrayList<>(); TreeNode current = root; while (current != null) { list.add(current); if (e.compareTo(current.element) < 0) { current = current.left; } else if (e.compareTo(current.element) > 0) { current = current.right; } else { break; } } return list; } public boolean delete(E e) { TreeNode parent = null; TreeNode current = root; while (current != null) { if (e.compareTo(current.element) < 0) { parent = current; current = current.left; } else if (e.compareTo(current.element)> 0) { parent = current; current = current.right; } else { break; } } if (current == null) { return false; } if (current.left == null) { if (parent == null) { root = current.right; } else { if (e.compareTo(parent.element) < 0) { parent.left = current.right; } else { parent.right = current.right; } } } else { TreeNode parentOfRightMost = current; TreeNode rightMost = current.left; while (rightMost.right != null) { parentOfRightMost = rightMost; rightMost = rightMost.right; } current.element = rightMost.element; if (parentOfRightMost.right == rightMost) { parentOfRightMost.right = rightMost.left; } else { parentOfRightMost.left = rightMost.left; } } size–; return true; } public Iterator iterator() { return new InorderIterator(); } public void clear() { root = null; size = 0; } private class InorderIterator implements Iterator { private ArrayList list = new ArrayList<>(); private int current = 0; public InorderIterator() { inorder(); } private void inorder() { inorder(root); } private void inorder(TreeNode root) { if (root == null) return; inorder(root.left); list.add(root.element); inorder(root.right); } public boolean hasNext() { return current < list.size(); } public E next() { return list.get(current++); } public void remove() { delete(list.get(current)); list.clear(); inorder(); } }}///////////////////////////////////////////////////////////////////////////////////////////////////////////TreeNode.Javapublic class TreeNode { protected E element; protected TreeNode left; protected TreeNode right; public TreeNode(E e) { element = e; } public String toString() { return element.toString(); }}Computer ScienceEngineering & TechnologyJava ProgrammingCIS MISCShare Question

Get a plagiarism-free order today   we guarantee confidentiality and a professional paper and we will meet the deadline.    

Leave a Reply

Order a plagiarism free paper today. Get 20% off your first order!

X