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

Leaves- Yitgop #46

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

Leaves- Yitgop #46

wants to merge 6 commits into from

Conversation

rinostar
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.

You clearly have the general idea on how to work with binary trees. That said there are a number of bugs here and some issues with time/space complexity. Take a look at my comments/suggestions and let me know any questions you have.

lib/tree.rb Outdated
Comment on lines 19 to 21
# Time Complexity: O(log n)
# Space Complexity: O(log n)
def add_helper(curr, key, value)

Choose a reason for hiding this comment

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

👍

lib/tree.rb Outdated
Comment on lines 39 to 41
# Time Complexity: O(log n)
# Space Complexity: O(log n)
def find(key)

Choose a reason for hiding this comment

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

👍

Comment on lines +57 to +59
# Time Complexity: O(n)
# Space Complexity: O(n)
def inorder_helper(curr, list)

Choose a reason for hiding this comment

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

👍

lib/tree.rb Outdated
Comment on lines 71 to 73
# Time Complexity: O(n)
# Space Complexity: O(log n)
def preorder_helper(curr, list)

Choose a reason for hiding this comment

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

👍

lib/tree.rb Outdated
Comment on lines 85 to 87
# Time Complexity: O(n)
# Space Complexity: O(log n)
def postorder_helper(curr, list)

Choose a reason for hiding this comment

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

Suggested change
# Time Complexity: O(n)
# Space Complexity: O(log n)
def postorder_helper(curr, list)
# Time Complexity: O(n)
# Space Complexity: O(n) - since you're building a list
def postorder_helper(curr, list)

lib/tree.rb Outdated
Comment on lines 106 to 107
left = height_helper(curr.left, height + 1)
right = height_helper(curr.right, height + 1)

Choose a reason for hiding this comment

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

Suggested change
left = height_helper(curr.left, height + 1)
right = height_helper(curr.right, height + 1)
left = height_helper(curr.left, height + 1)
right = height_helper(curr.right, height + 1)
return [left, right].max

lib/tree.rb Outdated
def height_helper(curr, height)
return height if curr.nil?

height = [left, right].max

Choose a reason for hiding this comment

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

What are left and right?

Suggested change
height = [left, right].max


inorder_helper(curr.left, list)
list << {key: curr.key, value: curr.value}
inorder_helper(curr.right, list)

Choose a reason for hiding this comment

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

Just for clarity on what's being returned, this is a minor suggestion.

Suggested change
inorder_helper(curr.right, list)
inorder_helper(curr.right, list)
return list

lib/tree.rb Outdated
Comment on lines 34 to 36
@root = TreeNode.new(key, value) if @root.nil?

return add_helper(@root, key, value)

Choose a reason for hiding this comment

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

Suggested change
@root = TreeNode.new(key, value) if @root.nil?
return add_helper(@root, key, value)
@root = add_helper(@root, key, value)

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.

3 participants