Conversation
|
Grabbing this to grade! |
chimerror
left a comment
There was a problem hiding this comment.
Good work!
I added some comments about a slight performance problem with your implementation for adding nodes, and a comment about commented code that can be removed. But overall, this is good enough for a Green!
|
|
||
| else: | ||
| current_root.right = self.add_helper(current_root.right, new_node) | ||
| return current_root |
There was a problem hiding this comment.
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 25 and 28.
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!
| # inorder = self.root | ||
| # inorder(self.root.left) | ||
|
|
||
| # inorder(self.root.right) |
There was a problem hiding this comment.
Looks like there's some commented code here. It's not a big deal in this case, but usually as a style thing, I recommend getting rid of commented code just to keep the code cleaner in general.
No description provided.