Skip to content

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.


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

👍

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


# 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