Open
Conversation
CheezItMan
reviewed
Dec 3, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Lacy, except for building an inverted tree your solution works for most of the methods (just postorder is failing).
Comment on lines
+26
to
+35
| while current: | ||
| previous = current | ||
| if current.key > new_node.key: | ||
| current = current.left | ||
| else: | ||
| current = current.right | ||
| if previous.key > new_node.key: | ||
| previous.left = new_node | ||
| else: | ||
| previous.right = new_node |
There was a problem hiding this comment.
You are storing things that are less than the current node on the right side and elements greater than on the left side. This works, but you end up with an inverted tree.
That's why your postorder isn't working properly on the tests.
Comment on lines
+41
to
43
| # Time Complexity: O(logn) | ||
| # Space Complexity: O(1) | ||
| def find(self, key): |
Comment on lines
+57
to
59
| # Time Complexity: O(logn) | ||
| # Space Complexity: O(1) | ||
| def inorder(self): |
There was a problem hiding this comment.
👍 However the space and time complexities are O(n) due to the list you're building
Comment on lines
+94
to
96
| # Time Complexity: O(logn) | ||
| # Space Complexity: O(1) | ||
| def preorder(self): |
Comment on lines
+119
to
121
| # Time Complexity: O(logn) | ||
| # Space Complexity: O(1) | ||
| def postorder(self): |
| right_height = self.height_helper(node.right) | ||
| return max(left_height,right_height)+ 1 | ||
|
|
||
| def height(self): |
| return self.height_helper(self.root) | ||
|
|
||
|
|
||
| def bfs_helper(self,node,bfs_list): |
There was a problem hiding this comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.