Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion binary_search_trees/array_to_bst.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ def __init__(self, value, left = None, right = None):
self.left = left
self.right = right

def bst_helper(arr):
if arr:
this_node_index = len(arr) // 2
this_node_val = arr[this_node_index]
left_array = arr[0:this_node_index]
right_array = arr[(this_node_index + 1):]
left_node = bst_helper(left_array)
right_node = bst_helper(right_array)

result = TreeNode(this_node_val, left_node, right_node)
return result
else:
return None

def arr_to_bst(arr):
""" Given a sorted array, write a function to create a
Balanced Binary Search Tree using the elements in the array.
Return the root of the Binary Search Tree.
"""
pass
return bst_helper(arr)
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
attrs==20.3.0
iniconfig==1.1.1
packaging==20.8
pluggy==0.13.1
py==1.10.0
pyparsing==2.4.7
pytest==6.2.1
toml==0.10.2
attrs
iniconfig
packaging
pluggy
py
pyparsinG
pytest
toml