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

Ports - Elle #9

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

Ports - Elle #9

wants to merge 9 commits into from

Conversation

dev-elle-up
Copy link

Chris, can we go over big O again?

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. I like the helper methods, they look good. I would suggest either putting them in the TreeNode class or making them private helper methods rather than methods embedded in another method. I feel that inner methods break up the flow of the outer method, making it hard to read.

@@ -16,45 +16,127 @@ def initialize
@root = nil
end

# Time Complexity:
# Space Complexity:
# Time Complexity: O(logn) if the tree is balanced (best case), O(n) if tree is unbalanced (worst case)

Choose a reason for hiding this comment

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

👍

# Time Complexity:
# Space Complexity:
# Time Complexity: O(logn) if the tree is balanced (best case), O(n) if tree is unbalanced (worst case)
# 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 could use a bit of a refactor.


return @output if !@root

def analyzeInorder(current)

Choose a reason for hiding this comment

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

An inner method? I suggest either putting this method in TreeNode or making it a private helper method. Output doesn't need to be an instance variable.

return height_left > height_right ? (height_left + 1) : (height_right + 1)
end

findMaxHeight(@root)

Choose a reason for hiding this comment

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

Just for readability adding a return here would be good.

end

# Time Complexity:
# Space Complexity:
# Time Complexity: O(n-squared)

Choose a reason for hiding this comment

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

You hit each node just once, so I would say O(n) instead.

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