-
Notifications
You must be signed in to change notification settings - Fork 44
Tatiana Tree Practice #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| return breadth_first(node, array) | ||
| end | ||
|
|
||
| def breadth_first(node, arr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
| # Useful for printing | ||
| def to_s | ||
| return "#{self.inorder}" | ||
| puts "#{self.inorder}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 BTW I'm going to swipe these for C12
No description provided.