From bbd13956365f119f5f0aa4fa19a96628a8574d81 Mon Sep 17 00:00:00 2001 From: Shannon B <89764051+eggoweggo@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:03:42 -0700 Subject: [PATCH] finished binary tree function --- binary_search_trees/array_to_bst.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/binary_search_trees/array_to_bst.py b/binary_search_trees/array_to_bst.py index f69cc42..6e287fa 100644 --- a/binary_search_trees/array_to_bst.py +++ b/binary_search_trees/array_to_bst.py @@ -10,4 +10,9 @@ def arr_to_bst(arr): Balanced Binary Search Tree using the elements in the array. Return the root of the Binary Search Tree. """ - pass \ No newline at end of file + if not arr: + return None + middle_num = len(arr) // 2 + left_side = arr_to_bst(arr[:middle_num]) + right_side = arr_to_bst(arr[middle_num + 1:]) + return TreeNode(arr[middle_num], left_side, right_side) \ No newline at end of file