Question
In algorithms/python, for Binary Search Trees, given the below class definitions for Node and Tree class, complete the find_min function to return the node which has the minimum value in the BST:
class Node:
def __init__(self, data):
self.data = data
self.right_child = None
self.left_child = None

class Tree:
def __init__(self):
self.root = None

# returns pointer to node with min value
def find_min(self):
####  IMPLEMENT THIS FUNCTION BODY #####

    def find_min(self):
current = self.root
while current and current.left_child:
current = current.left_child
return current
^^^ the algorithm for above function is basically based on fact that in BST, by design, the smallest value is the left most node (just like the largest is right most node)
^^^ note that the "while current" part of "while current and current.left_child) is there to take care of case that self.root is None

Question
In algorithms/python, for Binary Search Trees, given the below class definitions for Node and Tree class, complete the find_min function to return the node which has the minimum value in the BST:
class Node:
def __init__(self, data):
self.data = data
self.right_child = None
self.left_child = None

class Tree:
def __init__(self):
self.root = None

# returns pointer to node with min value
def find_min(self):
####  IMPLEMENT THIS FUNCTION BODY #####

?

Question
In algorithms/python, for Binary Search Trees, given the below class definitions for Node and Tree class, complete the find_min function to return the node which has the minimum value in the BST:
class Node:
def __init__(self, data):
self.data = data
self.right_child = None
self.left_child = None

class Tree:
def __init__(self):
self.root = None

# returns pointer to node with min value
def find_min(self):
####  IMPLEMENT THIS FUNCTION BODY #####

    def find_min(self):
current = self.root
while current and current.left_child:
current = current.left_child
return current
^^^ the algorithm for above function is basically based on fact that in BST, by design, the smallest value is the left most node (just like the largest is right most node)
^^^ note that the "while current" part of "while current and current.left_child) is there to take care of case that self.root is None
If you want to change selection, open document below and click on "Move attachment"

#### pdf

owner: kkhosravi - (no access) - PYTHON_DATA_STRUCTURES_AND_ALGORITHMS.pdf, p152

#### Summary

status measured difficulty not learned 37% [default] 0

No repetitions