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

Each node of a Binary Search Tree (B has an integer value and pointers to two ch

ID: 3837351 • Letter: E

Question

Each node of a Binary Search Tree (B has an integer value and pointers to two children, referred to as left child and right child. The value of left child is always less than the value of its parent node, and the value of right child is always greater than or equal to the value of its parent node he is Present function in your editor has to node of Binary Tree (BST) and an integer value two parameters: a reference the root a Search Complete is Present so it returns 1 ifthe value is present in the BST, and returns 0 otherwise. Constraints 1 total nodes s 10 1 s value s 5 x 104 Sample Input 0

Explanation / Answer

private static int isPresent(Node root, int val){
  
   if(root == null)
       return 0;

   if(root.data == val){
       return 1;
   }

   if(root.data < val)
       return isPresent(root.left, val);
   else
       return isPresent(root.right, val);
}

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