Open
Conversation
CheezItMan
reviewed
Sep 10, 2019
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work, I like how you worked through breadth first search. You made good use of helper methods and did a good job with the Big-O. I also like the tests you wrote.
| # Time Complexity: | ||
| # Space Complexity: | ||
| def bst_preorder(node, arr) | ||
| if !node |
There was a problem hiding this comment.
So if node is nil, you try to add the key & value to the list?
|
|
||
| # Time Complexity: | ||
| # Space Complexity: | ||
| # Time Complexity: O(log n) - omit half of dataset to add a value if tree is balanced |
There was a problem hiding this comment.
And O(n) if the tree is not balanced.
| # Time Complexity: | ||
| # Space Complexity: | ||
| # Time Complexity: O(n) because we visit each node once | ||
| # Space Complexity: O(h) where h is equal to height of tree unless tree is imbalanced, then O(n) |
| return breadth_first(node, array) | ||
| end | ||
|
|
||
| def breadth_first(node, arr) |
| # Useful for printing | ||
| def to_s | ||
| return "#{self.inorder}" | ||
| puts "#{self.inorder}" |
There was a problem hiding this comment.
Just a note, you can't test something being printed, it's easier to test a string result.
Plus you can always do: puts my_tree.to_s
| end | ||
| end | ||
|
|
||
| describe "bst height" do |
There was a problem hiding this comment.
👍 BTW I'm going to swipe these for C12
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.