Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
This is a great first attempt Theresa, but it looks like you may have strayed from the original problem a bit. I left some comments below to try and help redirect you. Please reach out (even after graduation) if you have questions or would like to go over this further.
| """ | ||
| pass No newline at end of file | ||
|
|
||
| class BinarySearch_tree: |
There was a problem hiding this comment.
It's a bit funky to define a class within a function. I'm not sure that it's not allowed but I believe it does create some weird situations with Python's rules about variable/object scope. We can actually create a binary search tree even without creating a BinarySearchTree class.
Notice from the Learn lessons (and your implementation!) that the BinarySearchTree class simply bundles together a single piece of data root with some functions. The root actually is the tree, in that it's the topmost node in the tree and via the child pointers we can reach all the other nodes in the tree.
We can uncouple the root and class methods, and simply use a variable root to represent the tree. Instead of class methods where the tree is passed in via self, each of our functions would instead need to have an explicit parameter root (or similar) to pass in the tree.
| def __init__(self) : | ||
| self.root = None | ||
|
|
||
| def insert(self, value): |
There was a problem hiding this comment.
You never call your insert function anywhere which is part of why many of the tests are failing. You have the logic written out, but it never gets used!
| mid_point = len(arr)//2 | ||
| if self.root == None: | ||
| self.root = TreeNode(arr[mid_point]) |
There was a problem hiding this comment.
Nice! Yes, the root should be the mid_point of the array.
| else: | ||
| self.insertNode(value, current_node.right) | ||
|
|
||
|
|
There was a problem hiding this comment.
It looks like you wrote out the logic to insert a node into a binary search tree which is great, but you're missing the logic to actually convert the array to the binary search tree.
No description provided.