| Operation on Binary Tree : | ||||||
Operations on Binary Tree are follows
|
||||||
| Searching | ||||||
| Searching a binary tree for a specific value is a process that can be performed recursively because of the order in which values are stored. At first examining the root. If the value is equals the root, the value exists in the tree. If it is less than the root, then it must be in the left subtree, so we recursively search the left subtree in the same manner. Similarly, if it is greater than the root, then it must be in the right subtree, so we recursively search the right subtree. If we reach a leaf and have not found the value, then the item does not lie in the tree at all. | ||||||
| Here is the search algorithm | ||||||
| search_btree(node, key): if node is None: return None // key not found if key < node.key: return search_btree(node.left, key) else if key > node.key: return search_btree(node.right, key) else : // key is equal to node key return node.value // found key |
||||||
| Prev | ||||||