minimum element in right sub tree, compare them with root data and select the one which is giving the

minimum value. This approach can be easily implemented with recursion.

import queue
class BinaryTreeNode:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def getData(self):
return self.data
def getLeft(self):
return self.left
def getRight(self):
return self.right
def insertLeft(self, newnode):
if self.left == None:
self.left = newnode
else:
newnode.left = self.left
self.left = newnode
def insertRight(self, newnode):
if self.right == None:
self.right = newnode
else:
newnode.right = self.right
self.right = newnode
minData = float("infinity")
def findMinRecursive(root):
global minData
if not root:
return minData
if root.getData() < minData:
minData = root.getData()
findMinRecursive(root.getLeft())
findMinRecursive(root.getRight())
return minData
A = BinaryTreeNode(90)
B = BinaryTreeNode(80)
C = BinaryTreeNode(30)
D = BinaryTreeNode(20)
E= BinaryTreeNode(10)
F = BinaryTreeNode(230)
G = BinaryTreeNode(45)
A.insertLeft(B)
A.insertRight(C)
B.insertLeft(D)
B.insertRight(E)
C.insertLeft(F)
C.insertRight(G)
print(findMinRecursive(A))

10

>>>

## Comments