show all steps-python
Review the following BST and create the inorder, preorder and postorder list.
Follow both algorithms. If the node has a left child
and a right child, 1) replace the node’s value with the largest
value
in the left subtree and delete that value’s node from the left
subtree.
Or 2) replace the node’s value with the smallest value in the right subtree and delete that value’s node from the right subtree.
-What are the two possible values for deleting the root value, 50?
-After deleting the value 72 in the following BST, list the values in preorder traversal.

#Node class for implementing the BST
class Node:
def __init__(self,key):
self.left = None
self.right = None
self.val = key
#Insert function to insert new node into BST
def insert(root,key):
if root is None:
return Node(key)
if(root.val<key):
root.right = insert(root.right,key)
elif(root.val>key):
root.left = insert(root.left,key)
return root
#inorder tree traversal
def inorder(root):
if root:
inorder(root.left)
print(root.val,end=" ")
inorder(root.right)
#postorder tree traversal
def postOrder(root):
if root:
postOrder(root.left)
postOrder(root.right)
print(root.val,end=" ")
#preorder tree traversal
def preOrder(root):
if root:
print(root.val,end=" ")
preOrder(root.left)
preOrder(root.right)
#minimum value of the tree
def minimum(root):
while(root.left!=None):
root = root.left
return root.val
#maximum value of the tree
def maximum(root):
while(root.right!=None):
root = root.right
return root.val
#deleting the given value
def deleteNode(root, key):
if root is None:
return root
#if the key value is less than root value then
#it will lies in left subtree
if key < root.val:
root.left = deleteNode(root.left, key)
# If the key value is greater than the root value
# then it will lies in right subtree
elif(key > root.val):
root.right = deleteNode(root.right, key)
#or the key is root value
else:
# checking for root has one node or not
if root.left is None :
temp = root.right
root = None
return temp
elif root.right is None :
temp = root.left
root = None
return temp
#if root has two children
#then find the minimum value from it's right subtree
temp = minimum(root.right)
# Copy the inorder successor's content to this node
root.val = temp
# Delete the inorder successor
root.right = deleteNode(root.right , temp)
return root
if __name__=="__main__":
root = None
root = insert(root,50)
root = insert(root,17)
root = insert(root,12)
root = insert(root,23)
root = insert(root,9)
root = insert(root,14)
root = insert(root,19)
root = insert(root,72)
root = insert(root,54)
root = insert(root,67)
root = insert(root,76)
print("post order:",end=" ")
postOrder(root)
print("\npre order:",end=" ")
preOrder(root)
print("\nin order:",end=" ")
inorder(root)
#finding minimum value of root 50
print("\nminimum element is:",end=" ")
print(minimum(root))
#finding maximum value of root 50
print("maximum element is:",end=" ")
print(maximum(root))
#deleting 72
root = deleteNode(root,72)
#After deleting the 72 preorder
preOrder(root)
Follow the above indentation
The code:
#Node class for implementing the BST
class Node:
def __init__(self,key):
self.left = None
self.right = None
self.val = key
#Insert function to insert new node into BST
def insert(root,key):
if root is None:
return Node(key)
if(root.val<key):
root.right = insert(root.right,key)
elif(root.val>key):
root.left = insert(root.left,key)
return root
#inorder tree traversal
def inorder(root):
if root:
inorder(root.left)
print(root.val,end=" ")
inorder(root.right)
#postorder tree traversal
def postOrder(root):
if root:
postOrder(root.left)
postOrder(root.right)
print(root.val,end=" ")
#preorder tree traversal
def preOrder(root):
if root:
print(root.val,end=" ")
preOrder(root.left)
preOrder(root.right)
#minimum value of the tree
def minimum(root):
while(root.left!=None):
root = root.left
return root.val
#maximum value of the tree
def maximum(root):
while(root.right!=None):
root = root.right
return root.val
#deleting the given value
def deleteNode(root, key):
if root is None:
return root
#if the key value is less than root value then
#it will lies in left subtree
if key < root.val:
root.left = deleteNode(root.left, key)
# If the key value is greater than the root value
# then it will lies in right subtree
elif(key > root.val):
root.right = deleteNode(root.right, key)
#or the key is root value
else:
# checking for root has one node or not
if root.left is None :
temp = root.right
root = None
return temp
elif root.right is None :
temp = root.left
root = None
return temp
#if root has two children
#then find the minimum value from it's right subtree
temp = minimum(root.right)
# Copy the inorder successor's content to this node
root.val = temp
# Delete the inorder successor
root.right = deleteNode(root.right , temp)
return root
if __name__=="__main__":
root = None
root = insert(root,50)
root = insert(root,17)
root = insert(root,12)
root = insert(root,23)
root = insert(root,9)
root = insert(root,14)
root = insert(root,19)
root = insert(root,72)
root = insert(root,54)
root = insert(root,67)
root = insert(root,76)
print("post order:",end=" ")
postOrder(root)
print("\npre order:",end=" ")
preOrder(root)
print("\nin order:",end=" ")
inorder(root)
#finding minimum value of root 50
print("\nminimum element is:",end=" ")
print(minimum(root))
#finding maximum value of root 50
print("maximum element is:",end=" ")
print(maximum(root))
#deleting 72
root = deleteNode(root,72)
#After deleting the 72 preorder
preOrder(root)
show all steps-python Review the following BST and create the inorder, preorder and postorder list. Follow...
show all steps-python
Review the following BST and create the inorder, preorder and
postorder list.
Try to delete the value 17 and after deletion create the
inorder, preorder and postorder list.
Follow both algorithms. If the node has a left child
and a right child, 1) replace the node’s value with the largest
value
in the left subtree and delete that value’s node from the left
subtree.
Or 2) replace the node’s value with the smallest value in the
right subtree...
show all steps
Review the following BST and create the inorder, preorder and
postorder list.
Try to delete the value 17 and after deletion create the
inorder, preorder and postorder list.
Follow both algorithms. If the node has a left child
and a right child, 1) replace the node’s value with the largest
value
in the left subtree and delete that value’s node from the left
subtree.
Or 2) replace the node’s value with the smallest value in the
right subtree...
JAVA CODE Topic: BST Animation For each task, submit the source code with detail comments. Objective: javafx GUI program for BST Animation. BSTAnimation.java, AbstractTree.java and Tree.java. Modify the BSTAnimation.java (1) Add Show Preoreder and Show Postorder button. Insert these two buttons next to the Show Inorder button to display tree in selected order. (2) Currently removing node method is to replace the removed node by the highest node on left-subtree. Modify the method by using lowest node on the right-subtree instead....
QUESTION 8 In the _____ traversal, the root is processed first, before its subtrees. breadth first preorder postorder inorder 0.10000 points QUESTION 9 What kind of traversal does the following algorithm (in pseudo-code) describe? Algorithm traversal (root) if (root is not null) traversal (leftSubTree) process (root) traversal (rightSubTree) end if end traversal breadth first preorder inorder postorder 0.10000 points QUESTION 10 What kind of traversal does the following algorithm (in pseudo-code) describe? Algorithm traversal (root) if...
write a new test program called RemoveDuplicates.java. The program reads text input from keyboard or a text file and adds the words to a BST. The program then traverses the BST and prints out the words in order (based on ASCII/UNICODE order) on the screen (or to output text file). Note that you may need to make some changes to BST.java. Sample test: ----jGRASP exec: java -ea removeDuplicates Original Text: a B 2 n w C q K l 0...
Please I need help ASAP Java Programing: Binary Search Tree Fully implement the BST class in Listing 25.4 (on page 961 of the 11th Edition of the text). Design and write a (main) driver program to completely test every method in the BST class to ensure the class meets all its requirements. You should read the Listing 25.5: TestBST.java for an idea of what your program should look like. Listing 25.4 BST.java public class BST> extends AbstractTree { protected TreeNode...
Using the following implementation of Tree class Node { public int iData; // data item (key) public double dData; // data item public Node leftChild; // this node's left child public Node rightChild; // this node's right child public void displayNode() // display ourself { System.out.print('{'); System.out.print(iData); System.out.print(", "); System.out.print(dData); System.out.print("} "); } } // end class Node //------------------------------------------------------------------ import java.io.IOException; import java.util.Stack; public class Tree { private Node root; // first node of tree // ------------------------------------------------------------- public Tree() // constructor { root = null; }...
using java to write,show me the output. please write some
common.
You CAN NOT use inbuild functions for Tree ADT operations.
using code below to finsih
public class Main
{
public static void main(String[] args) {
BinaryTree tree = new
BinaryTree();
tree.root = new Node(1);
tree.root.left = new Node(2);
tree.root.right = new Node(3);
tree.root.left.left = new Node(4);
tree.root.left.right = new Node(5);
tree.root.right.left = new Node(6);
tree.root.right.right = new Node(7);
tree.root.left.left.left = new Node(8);
tree.root.left.left .right= new Node(9);...
I need help to write this code in C++, I am struggling to find
max node's parent's right child and max node's left child.
Node* maxValueNode(Node* node)
{
Node* current = node;
while (current && current->right !=
NULL)
current = current->right;
return current;
}
void deleteNode(BST* tree, Node* node, Node* parent)
{
//TODO - follow the lecture pseudocode to write the
deleteNode function
// - returns true if the value was deleted, false if
not
// - don't forget to...
Start with the tree.java program (Listing 8.1) and modify it to create a binary tree from a string of letters (like A, B, and so on) entered by the user. Each letter will be displayed in its own node. Construct the tree so that all the nodes that contain letters are leaves. Parent nodes can contain some non-letter symbol like +. Make sure that every parent node has exactly two children. Don’t worry if the tree is unbalanced. Note that...