-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fire - blaine #28
base: master
Are you sure you want to change the base?
Fire - blaine #28
Conversation
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.
Awesome work Blaine, this hits the learning goals.
I did have comments on time/space complexity. Let me know if you have questions.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 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.
# Time Complexity: O(log n) | ||
# Space Complexity: O(1) | ||
def find(key) |
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.
👍 Ditto on space/time complexity
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
# left-root-right | ||
def 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.
👍
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
# root-left-right | ||
def preorder |
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.
👍
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
# left-right-root | ||
def postorder |
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.
👍
# Time Complexity: O(n)^2 | ||
# Space Complexity: O(n) | ||
def height |
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.
👍 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.
No description provided.