Answered step by step
Verified Expert Solution
Question
1 Approved Answer
its data structure I need it fast please follow each task in both labs it completes each other Trees, Binary search trees Lab 6 Task
its data structure I need it fast
Trees, Binary search trees Lab 6 Task 1 We define the following class Node class Nodef int data; Node left: Node right; public Node(int data)\{ this,data = data; left = null; right = null; 1 public String toString()/ return datat" Task 2 Define the class BST public class Bst f Node root; public Bst() f root = null; ) Task 3 Complete the iterative implementation below to insert a key in a BST: public void insert(int x ) Node n = new Node (x); Task 4 Complete the recursive implementation below to insert a key in a BST: private void insertRf Node start, int x)} public void insertRec ( int x) t insertR(root,x); Task 5 (Done) Complete the implementation below to search for the minimum in a BST: private int minimami Woste rootif int min = root.data; while (root.left 1 - hulf)! min = root.left data: root = root.left: 1 retum min; 1 Task 6 (Done) Complete the implementation below to delete an element in a BST: private Node delete_Recursive(Noule toat, int luty)f if (root w nell) return root, if (key root data) it taverie ripht suhtrec root,righ = delcte_Recursive(rootright, key): clsef. N aode contains oaly ane chaid if (rootleft muli) returit root.right: the if (root.right = aull) return root.beft; root.data = minimum( root right) root.right = delete_Recursive(root.right, root.data) 1 returu root; ) void delele(int keyy) ? root = delete_ Recursive(root, key). Lab 7 Task 7 Create the following Tree on slide 26 using the methods implemented in Lab 6. Task 8 Implement the methods inorder, preorder and postorder seen in the lecture. Task 9 Apply the methods implemented in Task 8 to the Tree and verify that you obtain the following results : Preorder Traversal: 3,13,22,19,26,54,71,33,14,11,87,8,56,9,75,28,15,10,63,36,7,69, 59,68,44 Inorder Traversal: 54,26,71,19,22,11,14,33,8,87,56,13,9,75,3,63,10,15,28,59,69,68 7,36,44 Postorder Traversal: 54,71,26,19,11,14,8,56,87,33,22,75,9,13,63,10,15,59,68,69,7,44, 36 282 please follow each task in both labs it completes each other
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started