Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Branches - Diana Han #38

wants to merge 2 commits into from

Conversation

dhan0406
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a 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.

Comment on lines +57 to 59
# Time Complexity: O(n)
# Space Complexity: O(1)
def add(key, value)

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?

Comment on lines +70 to +76
until current.key == key
if current.key > key
current = current.left
else
current = current.right
end
end

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?

Suggested change
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

Comment on lines +89 to 91
# Time Complexity: O(n)
# Space Complexity: O(n) n represents the number of nodes in a tree
def inorder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +104 to 106
# Time Complexity: O(n)
# Space Complexity: O(n)
def preorder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +119 to 121
# Time Complexity: O(n)
# Space Complexity: O(n)
def postorder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +138 to 140
# Time Complexity: O(n)
# Space Complexity: O(1)
def height

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants