Open
Conversation
CheezItMan
reviewed
Jan 11, 2022
CheezItMan
left a comment
There was a problem hiding this comment.
Well done Gloria. You hit the learning goals here. Nice work.
Comment on lines
+21
to
23
| # Time Complexity: O(n) because looping through all the nodes | ||
| # Space Complexity: O(n) because you need to add a node for each key, value | ||
| def add(self, key, value = None): |
There was a problem hiding this comment.
👍 The time complexity is O(n log n ) if the tree is balanced and O(n) otherwise.
Comment on lines
+42
to
+44
| def create_dict(self, TreeNode): | ||
| return { "key": TreeNode.key, | ||
| "value": TreeNode.value } |
There was a problem hiding this comment.
Useful helper, maybe put this in the TreeNode class.
Comment on lines
+47
to
50
| # Time Complexity: log(n) because we are examining only half of the nodes | ||
| # Space Complexity: O(1) because we are not allocating any memory | ||
| # self refers to object the class is making | ||
| def find(self, key): |
There was a problem hiding this comment.
👍 The time complexity is O(n log n ) if the tree is balanced and O(n) otherwise.
|
|
||
|
|
||
|
|
||
| def inorder(self): |
Comment on lines
+105
to
107
| # Time Complexity: 0(N) | ||
| # Space Complexity: Space Complexity: 0(N) depends on input size | ||
| def preorder(self): |
Comment on lines
+117
to
119
| # Time Complexity: 0(N) | ||
| # Space Complexity: 0(N) depends on input size | ||
| def postorder(self): |
Comment on lines
+128
to
+130
| # Time Complexity: 0(1) constant time | ||
| # Space Complexity: 0(1) | ||
| def height(self): |
There was a problem hiding this comment.
👍 this is O(n) for time complexity and O(n) space complexity if the tree is unbalanced and O(log n) if the tree is balanced.
| # Before pop head get info of current node add dict to the final array | ||
| # Encue the children insert at the tail | ||
| # https://www.geeksforgeeks.org/level-order-tree-traversal/ | ||
| 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.