Trees: Difficult Solutions

Code Writing

Write out a function that will take in a list of unique values and create a binary search tree out of it.
def make_bst(lst):
    if lst == []:
        return BTree.empty
    label = lst[0]
    if len(lst) == 1:
        return BTree(label)
    less, greater = [], []
    for elem in lst:
        if elem > label:
            greater.append(elem)
        else:
            less.append(elem)
    left = make_bst(less)
    right = make_bst(greater)
    return BTree(label, left, right)

Write out a function that will take in a sorted list of unique elements and create a balanced binary search tree out of it. You may want to define the given function, find_median_index to help you.
def make_balanced_bst(sorted_lst):
    if sorted_lst == []:
        return BTree.empty
    else if len(sorted_lst) == 1:
        return BTree(sorted_lst[0])
    median_index = find_median_index(sorted_lst)
    label = sorted_lst(median_index)
    left = make_balanced_bst(sorted_lst[:median_index])
    right = make_balanced_bst(sorted_lst[median_index + 1:])
    return BTree(label, left, right)
def find_median_index(lst):
    return len(lst) // 2