<jupyter_start><jupyter_text>Explore Binary Search Tree Now try implementing a BST on your own. You'll use the same Node class as before:```pythonclass Node(object):    def __init__(self, value):        self.value = value        self.left = None        self.right = None```                This time, you'll implement search() and insert(). You should rewrite search() and not use your code from the last exercise so it takes advantage of BST properties. Feel free to make any helper functions you feel like you need, including the print_tree() function from earlier for debugging. You can assume that two nodes with the same value won't be inserted into the tree. Beware of all the complications discussed in the videos!  Try yourself here<jupyter_code>class Node(object):
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

class BST(object):
    def __init__(self, root):
        self.root = Node(root)

    def insert(self, new_val):
        self.insert_helper(self.root, new_val)

    def insert_helper(self, current, new_val):
        if current.value < new_val:
            if current.right:
                self.insert_helper(current.right, new_val)
            else:
                current.right = Node(new_val)
        else:
            if current.left:
                self.insert_helper(current.left, new_val)
            else:
                current.left = Node(new_val)

    def search(self, find_val):
        return self.search_helper(self.root, find_val)

    def search_helper(self, current, find_val):
        if current:
            if current.value == find_val:
                return True
            elif current.value < find_val:
                return self.search_helper(current.right, find_val)
            else:
                return self.search_helper(current.left, find_val)
        return False<jupyter_output><empty_output><jupyter_text>Test Cases<jupyter_code># Set up tree
tree = BST(4)

# Insert elements
tree.insert(2)
tree.insert(1)
tree.insert(3)
tree.insert(5)

# Check search
print ("Pass" if tree.search(4) else "Fail")
print ("Pass" if not tree.search(6) else "Fail")<jupyter_output>Pass
Pass
{'fraction_non_alphanumeric': 0.08663930688554491, 'fraction_numerical': 0.0031919744642042863, 'mean_word_length': 2.6264462809917357, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '442068', 'license': 'MIT', 'n_tokens_mistral': 638, 'n_tokens_neox': 615, 'n_words': 206, 'path': 'trees/.ipynb_checkpoints/explore_binary_search_tree-checkpoint.ipynb', 'repo_name': 'PRkudupu/Algo-python', 'size': '2193'}