Skip to content

binary_search_tree #45

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

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

binary_search_tree #45

wants to merge 1 commit into from

Conversation

ropeeps
Copy link

@ropeeps ropeeps commented Jun 17, 2022

No description provided.

@chimerror
Copy link

Grabbing this to grade!

Copy link

@chimerror chimerror left a comment

Choose a reason for hiding this comment

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

Good work!

I added some comments about your time and space complexity calculations throughout, but even with missing complexity calculations for height, I think this is good enough for a Green.

return None

# Time Complexity: O(log n)
# Space Complexity: O(log n)

Choose a reason for hiding this comment

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

Good news! Since you did an iterative implementation of find, you don't take the hit of the extra stack frames you get from recursion, so your space complexity here is actually O(1), since no new memory is allocated.

return self.inorder_helper_function(self.root, values)

# Time Complexity: O(log n)
# Space Complexity: O(log n)

Choose a reason for hiding this comment

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

Note that unlike add and find where you only traverse down one branch of the tree, with the depth-first traversals, you do travel to every node in the tree, bumping up the space and time complexities to O(n).

This is the case for inorder, preorder, and postorder, so I won't repeat this there.

return max(self.height_helper(current.left), self.height_helper(current.right)) + 1

def height(self):
return self.height_helper(self.root)

Choose a reason for hiding this comment

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

It doesn't seem you added a time or space complexity calculation for your implementation of height, but I am not going to move down to a Yellow, but I do encourage you to think through it.

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