Finding the minimum node of a BST
In this exercise, you will practice on a BST to find the minimum node.
To test your code, you can use the following tree:

It has been preloaded in the bst variable (line 14):
bst = CreateTree()
You can print the result that returns the find_min() method with this code (line 15):
print(bst.find_min())
Latihan ini adalah bagian dari kursus
Data Structures and Algorithms in Python
Petunjuk latihan
- Set
current_nodeas the root. - Iterate over the nodes on the appropriate subtree.
- Update the value for
current_node.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
class BinarySearchTree:
def __init__(self):
self.root = None
def find_min(self):
# Set current_node as the root
current_node = ____
# Iterate over the nodes of the appropriate subtree
while current_node.____:
# Update current_node
current_node = current_node.____
return current_node.data
bst = CreateTree()
print(bst.find_min())