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 - Erika #45

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

Branches - Erika #45

wants to merge 9 commits into from

Conversation

emaust
Copy link

@emaust emaust commented Feb 27, 2020

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've got some bugs and some issues with time/space complexity. Take a look at my comments and suggestions and let me know if you have questions. It looks like you had trouble debugging this. You are welcome to use my office hours or the online TA Matt, if you like for additional support.

lib/tree.rb Outdated
Comment on lines 147 to 149
Erika Maust <[email protected]>
9:13 PM (1 minute ago)
to erika.maust

Choose a reason for hiding this comment

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

Suggested change
Erika Maust <erika.maust@gmail.com>
9:13 PM (1 minute ago)
to erika.maust

lib/tree.rb Outdated

# Time Complexity:
# Space Complexity:
def add(key, value)

Choose a reason for hiding this comment

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

👍 , just what's the space/time complexity?

lib/tree.rb Outdated
@root = TreeNode.new(key,value)
else
current = @root
while true

Choose a reason for hiding this comment

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

This loop is going to run forever...

lib/tree.rb Outdated
Comment on lines 44 to 46
# Time Complexity: Because it's recursive I want to say O log(n)
# Space Complexity: O log (n) if it's balanced, and I guess O(n) if it isn't
def find(key)

Choose a reason for hiding this comment

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

Because it's a binary tree the time complexity is O(log n) for a balanced tree and O(n) if it's not a balanced tree.

lib/tree.rb Outdated
Comment on lines 63 to 65
# Time Complexity: I think time and space are both O(n)?
# Space Complexity:
def inorder

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 79 to 81
# Time Complexity: I feel like both are O(n) since each item has to be traversed, even if it's recursively?
# Space Complexity:
def preorder

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 96 to 98
# Time Complexity: Same as above, O(n)?
# Space Complexity:
def postorder

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 114 to 116
# Time Complexity: I'm not sure about time and space here. I think O(n)
# Space Complexity:
def height

Choose a reason for hiding this comment

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

Time complexity is O(n) since you visit each node once. Space complexity depends on the height of the tree so it's O(log n) for a balanced tree and O(n) for an unbalanced tree.

lib/tree.rb Outdated
current.left = TreeNode.new(key,value)
end
else
if [email protected]?

Choose a reason for hiding this comment

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

What is @current?

Suggested change
if !@current.right.nil?
if !current.right.nil?

lib/tree.rb Outdated
Comment on lines 105 to 106
preorder_helper(current_node.left, list)
preorder_helper(current_node.right, list)

Choose a reason for hiding this comment

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

Suggested change
preorder_helper(current_node.left, list)
preorder_helper(current_node.right, list)
postorder_helper(current_node.left, list)
postorder_helper(current_node.right, list)

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.

Nice work, you hit the learning goals here. Well done Erika!

@@ -8,6 +8,87 @@ def initialize(key, val)
@left = nil
@right = nil
end

def add(key, value)

Choose a reason for hiding this comment

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

Nice adding these methods to the TreeNode class.

Comment on lines +100 to 102
# Time Complexity: O(log 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.

👍 , time complexity is right if the tree is balanced.

Comment on lines +113 to 115
# Time Complexity: O (log n)
# Space Complexity: O(1)
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 is right if the tree is balanced.

Comment on lines +122 to 124
# # Time Complexity: O(n)
# # Space Complexity: O(n)
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 +132 to 134
# # 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 +141 to 143
# # 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 +150 to 152
# # Time Complexity:
# # Space Complexity:
def height

Choose a reason for hiding this comment

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

👍 , time & space complexity?

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