-
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
Branches - Diana Han #38
base: master
Are you sure you want to change the base?
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.
Really nice work, you hit most of the learning goals here. Very elegantly written code. The only issue is with find
, as it's not quite working, and you have some issues with space complexity, remember recursion incurs space complexity. Check out my comments and let me know any questions you have.
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def add(key, value) |
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.
This method is recursive so it's going to have some space complexity. What do you think it is?
until current.key == key | ||
if current.key > key | ||
current = current.left | ||
else | ||
current = current.right | ||
end | ||
end |
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.
What about if the key is not in the tree? What about when current
is nil
?
until current.key == key | |
if current.key > key | |
current = current.left | |
else | |
current = current.right | |
end | |
end | |
until current.key == key | |
if current.key > key | |
current = current.left | |
else | |
current = current.right | |
end | |
return nil if current.nil? | |
end |
# Time Complexity: O(n) | ||
# Space Complexity: O(n) n represents the number of nodes in a tree | ||
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) | ||
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) | ||
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) | ||
# Space Complexity: O(1) | ||
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.
Note that this is a recursive method so you're going to have space complexity due to the call stack.
No description provided.