Write a function to find the node with minimum value in a Binary Search Tree

Simple logic . Just traverse the node from root to left recursively until left is NULL. The node whose left is NULL is the node with minimum value .

Code :

/* Given a non-empty binary search tree,
return the minimum data value found . */

int minValue(struct node* node) {
  struct node* current = node;
 
  /* loop down to find the leftmost leaf */
  while (current->left != NULL) {
    current = current->left;
  }

  return(current->data);
}

Time Complexity : O(H) where H is the height of the tree .

Leave a Reply

Your email address will not be published. Required fields are marked *

For Inserting code :
Paste your code in the comment form, select it and then click the language link

C | C++ | Java |

*