-
Notifications
You must be signed in to change notification settings - Fork 68
Ainur-Pine C16 #46
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
base: master
Are you sure you want to change the base?
Ainur-Pine C16 #46
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.
✨😎 Excellent work, Ainur. All the test cases that were failing were just due to a missing else
statement. We can discuss any questions you may have in our next session.
🟢
# Time Complexity: | ||
# Space Complexity: | ||
# BST is not empty | ||
self.insert_node_helper(self.root, 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.
Without the else
you add the root twice to the list. The tests for add
don't fully cover this case, but it reveals itself with the remaining functions where you print out the tree or try and find the height because there's an extra node in the tree. Making this change should allow you to pass all the tests.
self.insert_node_helper(self.root, key, value) | |
else: | |
self.insert_node_helper(self.root, key, value) |
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(log N) or O(n) | ||
# Space Complexity: O(n) |
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.
Space complexity would be same as time complexity based on the recursive call stack: O(log n) for balanced trees and O(n) for unbalanced trees.
|
||
|
||
# Time Complexity: O(log N) or O(n) | ||
# Space Complexity: O(n) | ||
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.
✨ However space complexity would be O(1) here since you did this iteratively and aren't creating any additional data structures whose size is proportional to the size of the tree.
# Space Complexity: | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
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.
✨
# Space Complexity: | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def preorder_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: O(n) | ||
# Space Complexity: O(n) | ||
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.
✨
# Space Complexity: | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
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.
Because of the recursive call stack, space complexity would also be O(n) here
# # Space Complexity: | ||
# # 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.