Open
Conversation
CheezItMan
reviewed
Jan 14, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Abigail, I added some feedback for minor improvements. Let me know if you have questions.
Comment on lines
17
to
19
| # Time Complexity: | ||
| # Space Complexity: | ||
| def add(self, key, value = None): |
| self.root = TreeNode(key,value) | ||
| current = self.root | ||
|
|
||
| while True: |
There was a problem hiding this comment.
Just a personal note. I dislike while True loops which depend on break statements to control the flow of execution because it makes the loop harder to trace and understand.
Comment on lines
43
to
45
| # Time Complexity: | ||
| # Space Complexity: | ||
| def find(self, key): |
Comment on lines
56
to
58
| # Time Complexity: | ||
| # Space Complexity: | ||
| def inorder(self): |
| left_part= helper(node.left) | ||
| middle_part = [{"key":node.key,"value":node.value}] | ||
| right_part = helper(node.right) | ||
| result = left_part + middle_part + right_part |
There was a problem hiding this comment.
Just a note that doing so much array concatenation is expensive rather than concatenating to the same area each time.
Comment on lines
72
to
74
| # Time Complexity: | ||
| # Space Complexity: | ||
| def preorder(self): |
Comment on lines
86
to
88
| # Time Complexity: | ||
| # Space Complexity: | ||
| def postorder(self): |
|
|
||
| queue.append(self.root) | ||
| while queue != []: | ||
| temp = queue.pop(0) |
There was a problem hiding this comment.
Just a note that queue.pop(0) is an O(n) operation. Python does have a deque data structure which provides a similar O(1) operation.
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.