Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 03db552

Browse files
Create Is_Binary_Tree a BST
Checks if a Binary Tree is a Binary Search Tree in the most efficient way.
1 parent a9e95a2 commit 03db552

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

‎Is_Binary_Tree a BST

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import math
2+
def is_BST(root, minVal, maxVal):
3+
if root == None:
4+
return True
5+
if minVal<root.data<maxVal and is_BST(root.left, minVal, root.data) and is_BST(root.right, root.data, maxVal):
6+
return True
7+
def check_binary_search_tree_(root):
8+
return is_BST(root, -math.inf, math.inf)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /