Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
April 24, 2024
class TreeNode: def __init__(self, key): self.key = key self.left = None self.right = None # Example Usage # Creating nodes root = TreeNode(1) root.left = TreeNode(2) root.right = TreeNode(3) root.left.left = TreeNode(4) root.left.right = TreeNode(5) # Traversing the tree (In-order traversal) def in_order_traversal(node): if node: in_order_traversal(node.left) print(node.key, end=" ") in_order_traversal(node.right) print("In-order traversal:") in_order_traversal(root)
Here’s the textual representation of the binary tree created by the code:
1 / \ 2 3 / \ 4 5
The root of the tree is the node with the key 1.
The left child of 1 is the node with the key 2, and the right child is the node with the key 3.
The left child of 2 is the node with the key 4, and the right child is the node with the key 5.