Question: please help me write this piece of code and explain it in java static BSTNode insert ( BSTNode root, int key ) { / /

please help me write this piece of code and explain it in java static BSTNode insert(BSTNode root, int key)
{
// COMPLETE THIS FUNCTION
// YOU CAN USE ANY OF THE OTHER GIVEN, COMPLETED FUNCTIONS HERE
// If the tree is empty
// If the key is already present in the root node
// Otherwise, recur down the tree
// Return unchanged root pointer
}
// function to search in a BST, returns either node with key or null if not found
static BSTNode search(BSTNode root, int key)
{
// COMPLETE THIS FUNCTION
// YOU CAN USE ANY OF THE OTHER GIVEN, COMPLETED FUNCTIONS HERE
// Base Cases: root is null or key is present
// Key is greater than root's key
// Key is smaller than root's key
}
// function to delete node by key in a BST
static BSTNode delNode(BSTNode root, int x){
// COMPLETE THIS FUNCTION
// YOU CAN USE ANY OF THE OTHER GIVEN, COMPLETED FUNCTIONS HERE
// If root is null - base case
// If key to be searched is in a subtree
// If root matches with the given key
// Cases when root has no children
// root has only right child
// root has only left child
// When both children are present
// Return unchanged root pointer
}
also is there another way to write them and which method has the best time complexity and why? thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!