Skip to content

Conversation

@melissa-nguyen
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 Melissa, you hit the learning goals here. Well done! Take a look at my comments and let me know what questions you have, primarily on space/time complexity.

Comment on lines +31 to 33
# Time Complexity: O(log n) if tree is balanced
# Space Complexity: O(n) ?
def add(self, key, value = None):

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(log n) for a balanced tree and O(n) for an unbalanced one. Space complexity is the same due to the call stack.

Comment on lines +41 to +43
# Time Complexity: O(log n) if tree is balanced
# Space Complexity: O(n) ?
def find(self, key):

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(log n) for a balanced tree and O(n) for an unbalanced one. Space complexity is O(1) because you have an iterative solution!

Comment on lines +64 to 66
# Time Complexity: O(n)
# Space Complexity: Dependent on the size/height of tree, O(h)
def inorder(self):

Choose a reason for hiding this comment

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

👍 Because you're building a list of all the nodes, the space complexity is O(n)

Comment on lines +94 to 96
# Time Complexity: O(n)
# Space Complexity: Dependent on the size/height of tree, O(h)
def preorder(self):

Choose a reason for hiding this comment

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

👍 Because you're building a list of all the nodes, the space complexity is O(n)

Comment on lines +124 to 126
# Time Complexity: O(n)
# Space Complexity: Dependent on the size/height of tree, O(h)
def postorder(self):

Choose a reason for hiding this comment

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

👍 Because you're building a list of all the nodes, the space complexity is O(n)

Comment on lines +153 to 155
# Time Complexity: O(n)
# Space Complexity: Dependent on the size/height of tree, O(h)
def height(self):

Choose a reason for hiding this comment

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

👍 Nicely done!

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