MCPcopy Create free account
hub / github.com/geekcomputers/Python / is_bst

Function is_bst

binary_search_tree.py:147–159  ·  view source on GitHub ↗

Function to find is a binary tree is a binary search tree.

(node, lower_lim=None, upper_lim=None)

Source from the content-addressed store, hash-verified

145
146
147def is_bst(node, lower_lim=None, upper_lim=None):
148 """Function to find is a binary tree is a binary search tree."""
149 if lower_lim is not None and node.info < lower_lim:
150 return False
151 if upper_lim is not None and node.info > upper_lim:
152 return False
153 is_left_bst = True
154 is_right_bst = True
155 if node.left is not None:
156 is_left_bst = is_bst(node.left, lower_lim, node.info)
157 if is_left_bst and node.right is not None:
158 is_right_bst = is_bst(node.right, node.info, upper_lim)
159 return is_left_bst and is_right_bst
160
161
162def postorder(node):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected