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

Jesse Pope - CS Fun Tree Practice #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jessepope
Copy link

No description provided.

@chimerror
Copy link

Grabbing this to grade!

Copy link

@chimerror chimerror left a comment

Choose a reason for hiding this comment

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

Good work!

I added some notes about a small performance issue with your recursive implementation of adding nodes, as well as a comment about leaving old code around, but overall this is good enough for a Green!

else:
current_root.right = self.add_helper(current_root.right, new_node)

return current_root

Choose a reason for hiding this comment

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

This implementation of add_helper works, but definitely does a bit of extra work in setting nodes. Essentially, every node on the path to where the new node ends up will have either its left or right node "updated", though most of these will be updated to the exact same node. The only one that gets a meaningful update is whenever the bottom of the tree is reached and gets its left/right node updated to the new node. These updates happen in lines 20 and 23.

This probably will not be too bad of a performance hit, but there is a way that you can do this and just update only the node you need.

But this overall fine enough!

return

new_node = TreeNode(key, value)
self.add_helper(self.root, new_node)

Choose a reason for hiding this comment

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

Looks like this was an older recursive solution. Good on you for solving it both ways! And correctly at that!

However, do be careful about leaving old unused versions of code in your source code, whether they are commented out or not. Especially if they have have the same name as they do in this case. Just mainly a style thing about aiming to keep your code clean of clutter.

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