Skip to main content

Traverse

Minimum element in BST

Explanation

In a BST, the leftmost node contains the minimum value. We only need to traverse left children until we reach a leaf node.

Analysis

def minValue(self, root):
def dfs(node):
if not node:
return float("inf")
return min(node.data, dfs(node.left))

return dfs(root)