Open
Conversation
CheezItMan
reviewed
Apr 16, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Awesome work Blaine, this hits the learning goals.
I did have comments on time/space complexity. Let me know if you have questions.
Comment on lines
+19
to
+22
| # Time Complexity: O(log n) | ||
| # Space Complexity: [O(1)-if it's a loop] - why do I wanna say O(n)?? help me. | ||
| # Try with a while loop | ||
| def add(key, value = nil) |
There was a problem hiding this comment.
👍 The time complexity is O(n) if the tree is balanced and O(log n) if it is balanced.
Since you're doing recursion in add_helper the space complexity is the same as the time.
Comment on lines
+51
to
53
| # Time Complexity: O(log n) | ||
| # Space Complexity: O(1) | ||
| def find(key) |
Comment on lines
+71
to
74
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| # left-root-right | ||
| def inorder |
Comment on lines
+90
to
93
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| # root-left-right | ||
| def preorder |
Comment on lines
+107
to
110
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| # left-right-root | ||
| def postorder |
Comment on lines
+124
to
126
| # Time Complexity: O(n)^2 | ||
| # Space Complexity: O(n) | ||
| def height |
There was a problem hiding this comment.
👍 The time complexity is O(n) (not n^2)
The space complexity is O(log n) if the tree is balanced or O(n) if it's not. The space complexity is basically the height of the tree.
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.