Day 28 of 100 Days of Python
Practising DSA
I started Binary Tree today. It is a data structure where the top value of the tree is called Root. Its left side value is supposed to be smaller than root while the right side larger.
I made a Binary Tree structure in Python using Class.
1
2
3
4
5
6
7
8
9
10
11
12
13
# Binary Tree
class Node:
def __init__(self, key):
self.val = key
self.left = None
self.right = None
root = Node(50)
root.left = Node(30)
root.right = Node(70)
print("Root value ", root.val)
print("Left value ", root.left.val)
print("Right value ", root.right.val)
Output
1
2
3
Root value 50
Left value 30
Right value 70
This post is licensed under CC BY 4.0 by the author.