Open
Conversation
CheezItMan
reviewed
Dec 3, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Nataliia. You hit the learning goals here. Nice work with BFS. Well done
| # Tree Exercise | ||
|
|
||
| In this exercise you will implement, in Ruby, several Tree methods. | ||
| In this exercise you will implement, in Python, several Tree methods. |
Comment on lines
+24
to
+27
| # Time Complexity: O(log n) for balanced BST, O(n) for unbalanced | ||
| # Space Complexity: O(1) | ||
|
|
||
| def add_helper(self, current, key, value): |
There was a problem hiding this comment.
👍 , however the space complexity is O(log n) if the tree is balanced.
Comment on lines
+44
to
+47
| # Time Complexity: O(log n) for balanced BST, O(n) for unbalanced | ||
| # Space Complexity: O(1) | ||
|
|
||
| def find_helper(self, current, key): |
There was a problem hiding this comment.
👍 However due to the recursive stack, the space complexity is O(log n) for a balanced tree.
Comment on lines
+62
to
+66
| # Time Complexity: O(n), because we visit each node once | ||
| # Space Complexity: O(depth of the recursion) or O(h), where h is height | ||
| # of the tree -> O(n) in the worst case | ||
|
|
||
| def inorder_helper(self, current, result): |
Comment on lines
+82
to
+89
| # Time Complexity: ^ | ||
| # Space Complexity: ^ | ||
|
|
||
| def preorder_helper(self, current, result): | ||
| if current: | ||
| result.append(current.to_json()) | ||
| self.preorder_helper(current.left, result) | ||
| self.preorder_helper(current.right, result) |
Comment on lines
+99
to
+103
| # ----------- post-order ---------- | ||
| # Time Complexity: ^ | ||
| # Space Complexity: ^ | ||
|
|
||
| def postorder_helper(self, current, result): |
Comment on lines
+119
to
+122
| # Time Complexity: O(log n) for balanced, O(n) for unbalanced | ||
| # Space Complexity: O(n) | ||
|
|
||
| def height_helper(self, current): |
Comment on lines
+138
to
141
| # # Time Complexity: O(n) | ||
| # # Space Complexity:O(n) | ||
|
|
||
| def bfs(self): |
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.