-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mariela Cruz - Scissors #35
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
# Time Complexity: O(log n) - balanced tree | ||
# Space Complexity: O (log n) - recursive approach | ||
def add(self, key, value = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# parent.left = TreeNode(key,value) | ||
# else: | ||
# parent.right = TreeNode(key, value) | ||
# Time Complexity: O(log n) | ||
# Space Complexity: | ||
def find(self, key): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# helper function for pre order | ||
def preorder_helper(self, current, traversal_list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
self.preorder_helper(current.left, postorder_list) | ||
self.preorder_helper(current.right, postorder_list) | ||
postorder_list.append({"key": current.key,"value":current.value}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(logn) | ||
# Space Complexity: O (1) | ||
def height(self): |
There was a problem hiding this comment.
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.
2 bfs fail, 1 fail post order fail