Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary Search Tree Exercise #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

perugia33
Copy link

No description provided.

Copy link

@kyra-patton kyra-patton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


class BinarySearch_tree:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

self.root = None

def insert(self, value):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment on lines +23 to +25
if self.root == None:
self.root = TreeNode(arr[mid_point])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Yes, the root should be the mid_point of the array.

self.insertNode(value, current_node.right)


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants