-
Notifications
You must be signed in to change notification settings - Fork 68
binary_search_tree #45
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
base: master
Are you sure you want to change the base?
Conversation
Grabbing this to grade! |
There was a problem hiding this 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 comments about your time and space complexity calculations throughout, but even with missing complexity calculations for height
, I think this is good enough for a Green.
return None | ||
|
||
# Time Complexity: O(log n) | ||
# Space Complexity: O(log n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news! Since you did an iterative implementation of find
, you don't take the hit of the extra stack frames you get from recursion, so your space complexity here is actually O(1), since no new memory is allocated.
return self.inorder_helper_function(self.root, values) | ||
|
||
# Time Complexity: O(log n) | ||
# Space Complexity: O(log n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that unlike add
and find
where you only traverse down one branch of the tree, with the depth-first traversals, you do travel to every node in the tree, bumping up the space and time complexities to O(n).
This is the case for inorder
, preorder
, and postorder
, so I won't repeat this there.
return max(self.height_helper(current.left), self.height_helper(current.right)) + 1 | ||
|
||
def height(self): | ||
return self.height_helper(self.root) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem you added a time or space complexity calculation for your implementation of height
, but I am not going to move down to a Yellow, but I do encourage you to think through it.
No description provided.