Conversation
CheezItMan
reviewed
Apr 27, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Roshni, you hit the learning goals here. Well done.
Comment on lines
+19
to
+21
| # Time Complexity: O(log n) for balanced, O(n) for unbalanced | ||
| # Space Complexity: O(log n) for balanced, O(n) for unbalanced | ||
| def add(key, value = nil) |
Comment on lines
+40
to
+65
| # iterative add helper | ||
| # def add_helper(current, key, value) | ||
| # added_to_tree = false | ||
|
|
||
| # until added_to_tree | ||
| # if key <= current.key | ||
| # next_node = current.left | ||
| # if next_node.nil? | ||
| # new_node = TreeNode.new(key, value) | ||
| # current.left = new_node | ||
| # added_to_tree = true | ||
| # else | ||
| # current = current.left | ||
| # end | ||
| # else | ||
| # next_node = current.right | ||
| # if next_node.nil? | ||
| # new_node = TreeNode.new(key, value) | ||
| # current.right = new_node | ||
| # added_to_tree = true | ||
| # else | ||
| # current = current.right | ||
| # end | ||
| # end | ||
| # end | ||
| # end |
Comment on lines
+69
to
71
| # Time Complexity: O(log n) for balanced, O(n) for unbalanced | ||
| # Space Complexity: O(log n) for balanced, O(n) for unbalanced | ||
| def find(key) |
Comment on lines
+106
to
108
| # Time Complexity: O(n) to visit all nodes | ||
| # Space Complexity: O(n) values array depends on how many nodes there are | ||
| def inorder |
Comment on lines
+122
to
124
| # Time Complexity: O(n) to visit all nodes | ||
| # Space Complexity: O(n) values array depends on how many nodes there are | ||
| def preorder |
Comment on lines
+138
to
140
| # Time Complexity: O(n) to visit all nodes | ||
| # Space Complexity: O(n) values array depends on how many nodes there are | ||
| def postorder |
Comment on lines
+154
to
156
| # Time Complexity: O(n) to visit all the nodes | ||
| # Space Complexity: O(log n) if balanced, O(n) if unbalanced | ||
| def height |
Comment on lines
+170
to
173
| # Time Complexity: O(n^2) due to use of .shift | ||
| # Space Complexity: O(n) | ||
| # Solution from class | ||
| def bfs |
There was a problem hiding this comment.
👍 This should work, and good insight with the .shift's affect on the time complexity.
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.