Skip to content

Commit 7905091

Browse files
authored
Add files via upload
1 parent 4120036 commit 7905091

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Binary search Tree
2+
'''
3+
A binary search tree is type of binary tree in which all nodes of tree has key-value pairs.
4+
For All nodes in BST, the values of keys in left subtree of node is less than the value of node themselves. All keys in the right subtree have greter values than node.
5+
This is reffered as the BST Rule.
6+
NodeValue(Leftsubtree) <= NodeValue(Current) < NodeValue(RightSubtree)
7+
'''
8+
9+
# Implementing a Binary Search tree
10+
'''
11+
To implement BST, first we need a Node class
12+
A node class should have a value, a left child, a right child, a prent
13+
'''
14+
class Node:
15+
def __init__(self,val): # Constructor to intialize the value of the node
16+
self.val = val
17+
self.leftchild = None
18+
self.rightchild = None
19+
self.parent = None
20+
# Binary serach tree class
21+
class BinarySearchTree:
22+
def __init__(self, val): # intializes a root node
23+
self.root = Node(val)
24+
BST = BinarySearchTree(6)
25+
print(BST.root.val)

0 commit comments

Comments
 (0)