Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the following tree node definition TreeNode {TreeNode* left *right; Int val;

ID: 3581785 • Letter: U

Question

Use the following tree node definition TreeNode {TreeNode* left *right; Int val;} Given two binary trees, write a function to check if they are identical or not. By "identical", we mean two trees have exactly the same structure and key values. Void identical(TreeNode *T1, TreeNode * T2) ...//your implementation Given a node in binary search tree (BST) say x, design an algorithm to find the in-order successor of node x is the node with the smallest value greater than node xs value. Note that there is no link pointing back to a node's parent. An example BST is given for your reference.

Explanation / Answer

struct node* search(int searchdata){
struct node *current = root;
while(current->data != searchdata){
if(current != NULL) {
if (current->data==searchdata)
break;  
if(current->data > data) //go to left tree
current = current->leftChild;
else //else go to right tree
current = current->rightChild;
if(current == NULL) //not found
return NULL;      
}
return current->rightchild->data;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote