-
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
Nataliia Getlin - Rock - C15 #40
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 Nataliia. You hit the learning goals here. Nice work with BFS. Well done
@@ -1,6 +1,6 @@ | |||
# Tree Exercise | |||
|
|||
In this exercise you will implement, in Ruby, several Tree methods. | |||
In this exercise you will implement, in Python, several Tree methods. |
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.
Whoops
# Time Complexity: O(log n) for balanced BST, O(n) for unbalanced | ||
# Space Complexity: O(1) | ||
|
||
def add_helper(self, current, key, 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.
👍 , however the space complexity is O(log n) if the tree is balanced.
# Time Complexity: O(log n) for balanced BST, O(n) for unbalanced | ||
# Space Complexity: O(1) | ||
|
||
def find_helper(self, current, 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.
👍 However due to the recursive stack, the space complexity is O(log n) for a balanced tree.
# Time Complexity: O(n), because we visit each node once | ||
# Space Complexity: O(depth of the recursion) or O(h), where h is height | ||
# of the tree -> O(n) in the worst case | ||
|
||
def inorder_helper(self, current, result): |
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: ^ | ||
# Space Complexity: ^ | ||
|
||
def preorder_helper(self, current, result): | ||
if current: | ||
result.append(current.to_json()) | ||
self.preorder_helper(current.left, result) | ||
self.preorder_helper(current.right, result) |
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.
👍
# ----------- post-order ---------- | ||
# Time Complexity: ^ | ||
# Space Complexity: ^ | ||
|
||
def postorder_helper(self, current, result): |
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/space
# Time Complexity: O(log n) for balanced, O(n) for unbalanced | ||
# Space Complexity: O(n) | ||
|
||
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(n) | ||
# # Space Complexity:O(n) | ||
|
||
def bfs(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.
👍
No description provided.