Skip to content

Conversation

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

Well done Chelsea, you hit all the requirements. Nice work!

Comment on lines +20 to 22
# Time Complexity: log n because it is binary to find where to add the node
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n)
def add(key, value)

Choose a reason for hiding this comment

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

👍

Comment on lines +53 to 55
# Time Complexity: log n due to the binary search
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n)
def find(key)

Choose a reason for hiding this comment

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

👍

Comment on lines +78 to 80
# Time Complexity: O(n) because it has to go through every node.
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log 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 +102 to 104
# Time Complexity: O(n) because it has to go through every node.
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n)
def preorder

Choose a reason for hiding this comment

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

The space complexity for these traversals is O(n) because we're building an array.

With recursion it would be O(n + n) = O(2n) = O(n) or average case O(n + log n) = O(n)

Comment on lines +126 to 128
# Time Complexity: O(n) because it has to go through every node.
# Space Complexity: worst case O(n) because we hit every node, better average case like in a balanced tree it would be O(log n)
def postorder

Choose a reason for hiding this comment

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

👍 With the earlier note on the traversals.

Comment on lines +151 to 153
# Time Complexity: O(n) because we hit eery node
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n)
def height

Choose a reason for hiding this comment

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

👍

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