We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ea68ec2 commit bd22957Copy full SHA for bd22957
1 file changed
Min_depth_binary.py
@@ -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
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