Open
Conversation
CheezItMan
reviewed
Feb 27, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
I saw your comment, yes it is hard. This is one of the more difficult exercises.
Really nice work, you hit all the learning goals here. Very elegantly written code. Well done! You even had a good stab at the delete method.
Comment on lines
+12
to
+31
| def inorder(list) | ||
| list = left.inorder(list) unless left.nil? | ||
| list << {key: key, value: value} | ||
| list = right.inorder(list) unless right.nil? | ||
| return list | ||
| end | ||
|
|
||
| def preorder(list) | ||
| list << {key: key, value: value} | ||
| list = left.preorder(list) unless left.nil? | ||
| list = right.preorder(list) unless right.nil? | ||
| return list | ||
| end | ||
|
|
||
| def postorder(list) | ||
| list = left.postorder(list) unless left.nil? | ||
| list = right.postorder(list) unless right.nil? | ||
| list << {key: key, value: value} | ||
| return list | ||
| end |
There was a problem hiding this comment.
I like how you put these into the TreeNode class.
Comment on lines
+57
to
59
| # Time Complexity: O(1) | ||
| # Space Complexity: O1 | ||
| def find(key) |
There was a problem hiding this comment.
Time complexity constant? Really? Think about this a bit.
Comment on lines
+73
to
+75
| # Time Complexity: On | ||
| # Space Complexity: On | ||
| def inorder_helper |
Comment on lines
+89
to
91
| # Time Complexity: On | ||
| # Space Complexity: On | ||
| def preorder |
Comment on lines
+97
to
99
| # Time Complexity: On | ||
| # Space Complexity: On | ||
| def postorder |
| # Time Complexity: | ||
| # Space Complexity: | ||
| def max (num1, num2) |
Comment on lines
+115
to
120
| def height_helper(current) | ||
| return 0 if current.nil? | ||
| return 1 + max(height_helper(current.left), height_helper(current.right)) | ||
| end | ||
|
|
||
| def height |
| end | ||
|
|
||
| def delete(key) | ||
| value = self.find(key) |
There was a problem hiding this comment.
Not sure what value is doing?
This is a good start at the delete method, well done. It's not quite all the way.
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.
These are difficult for me. I'm having a hard time visualizing how the data is processed.