Skip to content

Conversation

@Blaine206
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.

Awesome work Blaine, this hits the learning goals.

I did have comments on time/space complexity. Let me know if you have questions.

Comment on lines +19 to +22
# Time Complexity: O(log n)
# Space Complexity: [O(1)-if it's a loop] - why do I wanna say O(n)?? help me.
# Try with a while loop
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 time complexity is O(n) if the tree is balanced and O(log n) if it is balanced.
Since you're doing recursion in add_helper the space complexity is the same as the time.

Comment on lines +51 to 53
# 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.

👍 Ditto on space/time complexity

Comment on lines +71 to 74
# Time Complexity: O(n)
# Space Complexity: O(n)
# left-root-right
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 +90 to 93
# Time Complexity: O(n)
# Space Complexity: O(n)
# root-left-right
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 +107 to 110
# Time Complexity: O(n)
# Space Complexity: O(n)
# left-right-root
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 +124 to 126
# Time Complexity: O(n)^2
# 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.

👍 The time complexity is O(n) (not n^2)

The space complexity is O(log n) if the tree is balanced or O(n) if it's not. The space complexity is basically the height of the tree.

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