Skip to content

Conversation

@marielaxcruz
Copy link

2 bfs fail, 1 fail post order fail

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 Mariela, you hit most of the learning goals. I spotted a few mistakes in postorder (mostly a typo). Otherwise great work.

Comment on lines +31 to +33
# Time Complexity: O(log n) - balanced tree
# Space Complexity: O (log n) - recursive approach
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.

👍

# parent.right = TreeNode(key, value)
# Time Complexity: O(log n)
# Space Complexity:
def find(self, key):

Choose a reason for hiding this comment

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

👍 Nice iterative solution

else:
current = current.right

def inorder_helper(self, current, inorder_list):

Choose a reason for hiding this comment

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

👍

Comment on lines +86 to +87
# helper function for pre order
def preorder_helper(self, current, traversal_list):

Choose a reason for hiding this comment

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

👍

Comment on lines +106 to +108
self.preorder_helper(current.left, postorder_list)
self.preorder_helper(current.right, postorder_list)
postorder_list.append({"key": current.key,"value":current.value})

Choose a reason for hiding this comment

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

Suggested change
self.preorder_helper(current.left, postorder_list)
self.preorder_helper(current.right, postorder_list)
postorder_list.append({"key": current.key,"value":current.value})
postorder_list.append({"key": current.key,"value":current.value})
self.postorder_helper(current.left, postorder_list)
self.postorder_helper(current.right, postorder_list)

self.postorder_helper(self.root, postorder_list)
return postorder_list

def height_helper(self, current):

Choose a reason for hiding this comment

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

👍

Comment on lines +126 to 128
# Time Complexity: O(logn)
# Space Complexity: O (1)
def height(self):

Choose a reason for hiding this comment

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

👍 Since the helper is recursive, we have O(log n) space complexity for a balanced 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