Advertisement
STANAANDREY

check bst py

Jan 16th, 2023 (edited)
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. arbore_binar_cautare = { "value" : 4, "left":
  2.                              {"value": 2, "left": {"value": 1, "left": None, "right": None}, "right": {"value": 3, "left": None, "right": None},
  3.                              }, "right":
  4.                              {"value": 7, "left": None, "right": None}
  5.                           }
  6.  
  7. def isBinSrcTree(tree):
  8.     def utilIsBinSrcTree(tree):
  9.         ok = True
  10.         if tree['left'] is not None:
  11.             ok &= tree['value'] > utilIsBinSrcTree(tree['left'])[1]
  12.         if tree['right'] is not None:
  13.             ok &= tree['value'] < utilIsBinSrcTree(tree['right'])[1]
  14.         return ok, tree['value']
  15.  
  16.     return utilIsBinSrcTree(tree)[0]
  17.  
  18. print(isBinSrcTree(arbore_binar_cautare))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement