Skip to content

Commit bd22957

Browse files
authored
1 parent ea68ec2 commit bd22957

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Min_depth_binary.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Node:
2+
def __init__(self, key):
3+
self.data = key
4+
self.left = None
5+
self.right = None
6+
7+
def min_height_binary(root):
8+
if(root==None):
9+
return 0
10+
else:
11+
ldepth=min_height_binary(root.left)
12+
rdepth = min_height_binary(root.right)
13+
14+
if(ldepth > rdepth):
15+
return 1+rdepth
16+
else:
17+
return 1+ldepth
18+
19+
20+
root = Node(1)
21+
root.left = Node(2)
22+
root.right = Node(3)
23+
root.left.left = Node(4)
24+
root.left.right = Node(5)
25+
root.left.left.right = Node(7)
26+
root.right.right = Node(6)
27+
28+
print(min_height_binary(root))
29+
30+
31+
32+
33+
34+

0 commit comments

Comments
 (0)