-
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
Leaves - Katie K #39
base: master
Are you sure you want to change the base?
Leaves - Katie K #39
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.
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.
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 |
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.
I like how you put these into the TreeNode
class.
# Time Complexity: O(1) | ||
# Space Complexity: O1 | ||
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.
Time complexity constant? Really? Think about this a bit.
# Time Complexity: On | ||
# Space Complexity: On | ||
def inorder_helper |
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: On | ||
# Space Complexity: On | ||
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: On | ||
# Space Complexity: On | ||
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: | ||
# Space Complexity: | ||
def max (num1, num2) |
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.
I like this little helper.
def height_helper(current) | ||
return 0 if current.nil? | ||
return 1 + max(height_helper(current.left), height_helper(current.right)) | ||
end | ||
|
||
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.
👍 Well done
end | ||
|
||
def delete(key) | ||
value = self.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.
Not sure what value is doing?
This is a good start at the delete
method, well done. It's not quite all the way.
These are difficult for me. I'm having a hard time visualizing how the data is processed.