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 - Katie K #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

KKennedyCodes
Copy link

These are difficult for me. I'm having a hard time visualizing how the data is processed.

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.

I saw your comment, yes it is hard. This is one of the more difficult exercises.

Really nice work, you hit all the learning goals here. Very elegantly written code. Well done! You even had a good stab at the delete method.

Comment on lines +12 to +31
def inorder(list)
list = left.inorder(list) unless left.nil?
list << {key: key, value: value}
list = right.inorder(list) unless right.nil?
return list
end

def preorder(list)
list << {key: key, value: value}
list = left.preorder(list) unless left.nil?
list = right.preorder(list) unless right.nil?
return list
end

def postorder(list)
list = left.postorder(list) unless left.nil?
list = right.postorder(list) unless right.nil?
list << {key: key, value: value}
return list
end

Choose a reason for hiding this comment

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

I like how you put these into the TreeNode class.

lib/tree.rb Show resolved Hide resolved
Comment on lines +57 to 59
# Time Complexity: O(1)
# Space Complexity: O1
def find(key)

Choose a reason for hiding this comment

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

Time complexity constant? Really? Think about this a bit.

Comment on lines +73 to +75
# Time Complexity: On
# Space Complexity: On
def inorder_helper

Choose a reason for hiding this comment

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

👍

Comment on lines +89 to 91
# Time Complexity: On
# Space Complexity: On
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 +97 to 99
# Time Complexity: On
# Space Complexity: On
def postorder

Choose a reason for hiding this comment

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

👍

# Time Complexity:
# Space Complexity:
def max (num1, num2)

Choose a reason for hiding this comment

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

I like this little helper.

Comment on lines +115 to 120
def height_helper(current)
return 0 if current.nil?
return 1 + max(height_helper(current.left), height_helper(current.right))
end

def height

Choose a reason for hiding this comment

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

👍 Well done

end

def delete(key)
value = self.find(key)

Choose a reason for hiding this comment

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

Not sure what value is doing?

This is a good start at the delete method, well done. It's not quite all the way.

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