Skip to main content

Posts

Showing posts with the label bst code

binary search tree

Binary search tree is a tree structure defined by the following rules: (1) for each parent node in the tree , the left child node value will be less than its value and the right child node value will be greater than its value. (2) there can not be any duplicate node. Clearly, creating a binary search tree, and searching a value in binary search tree works pretty much like bisection method; i.e. first we start with the root value, if it is lesser than the root value then we search with the lesser values only and if it greater than the root value, then we check with the greater values only. i.e. the algorithm looks like something below in pseudocode: search(value,node) {       if (node==NULL)      {         print(value not found )      }      elseif(value>node->data)      {           search(value,node->right)       }  ...