Binary Trees
Binary Trees Binary Trees Binary tree is data structure in which each node contains maximum of two children Binary search tree same as binary tree but sorted. Check whether given TREE is BST is_bst.python In [ 2 ]: # Node definition ...: class Node : ...: def __init__ ( self , value, left= None , right= None ): ...: self .value = value ...: self .left = left ...: self .right = right ...: def __str__ ( self ): ...: return str ( self .value) ...: In [ 3 ]: #define function to check given tree is binary search tree ...: #BST is a tree whose left.node.value<node.value and node.value<right.node.value ...: def is_bst (node, rnp_value = None , lnp_value = None ): ...: # if node.value < right.node.parent.value ...: if rnp_value and node.value < rnp_value: ...: return False ...: # if node.value > left.node.parent.value ...: