Skip to content

Commit c16162c

Browse files
authored
Inorder Traversal of Binary Tree
Inorder traversal is defined as a type of tree traversal technique which follows the Left-Root-Right pattern, such that: The left subtree is traversed first Then the root node for that subtree is traversed Finally, the right subtree is traversed
1 parent 610efa9 commit c16162c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Inorder Traversal of Binary Tree

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ class BinaryTree:
1313
self._inorder_recursive(node.left)
1414
print(node.value,end="->")
1515
self._inorder_recursive(node.right)
16+
# DEPTH/HEIGHT OF TREE
17+
def height(self,node):
18+
if node is None:
19+
return 0
20+
else:
21+
left_height=self.height(node.left)
22+
right_height=self.height(node.right)
23+
return max(left_height,right_height)+1
1624

1725
#Create nodes
1826
root=Node(10)
@@ -25,3 +33,4 @@ root.right.right=Node(54)
2533
tree=BinaryTree()
2634
tree.root1=root
2735
print(tree._inorder_recursive(tree.root1))
36+
print(tree.height(tree.root1))

0 commit comments

Comments
 (0)