Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Binary_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Python program to introduce Binary Tree

# A class that represents an individual node
# in a Binary Tree
class Node:
def __init__(self, key):
self.left = None
self.right = None
self.val = key


if __name__ == '__main__':
# Create root
root = Node(1)
''' following is the tree after above statement
1
/ \
None None'''

root.left = Node(2)
root.right = Node(3)
''' 2 and 3 become left and right children of 1
1
/ \
2 3
/ \ / \
None None None None'''

root.left.left = Node(4)
'''4 becomes left child of 2
1
/ \
2 3
/ \ / \
4 None None None
/ \
None None'''