Skip to content

Conversation

@indiakato
Copy link

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.

Nice work India, you hit the learning goals here. I left a few comments on space/time complexity, but otherwise this is all correct.

Comment on lines +29 to +31
# Time Complexity: O(logn)
# Space Complexity: O(logn)
def add(key, value = nil)

Choose a reason for hiding this comment

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

👍 the method is Log n if the tree is roughly balanced.

Comment on lines +47 to +50
# Time Complexity: O(logn)
# Space Complexity: O(logn)

def find(key, current = @root)

Choose a reason for hiding this comment

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

👍 the method is Log n if the tree is roughly balanced.

Comment on lines +63 to 65
# 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 +79 to 81
# 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 +95 to 97
# 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 +107 to 109
# Time Complexity: O(n)
# Space Complexity: O(n)
def height

Choose a reason for hiding this comment

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

👍 Because the recursion depth is dependent on the height of the tree it's O(log n) for space complexity for a balanced tree. It's O(n) if the tree isn't balanced.

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