Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
✨😎 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.
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.
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.
✨ 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): |
| # Space Complexity: | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def preorder_helper(self, current, result): |
|
|
||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def postorder_helper(self, current, result): |
| # Space Complexity: | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def height_helper(self, current): |
There was a problem hiding this comment.
Because of the recursive call stack, space complexity would also be O(n) here
| # # Time Complexity: O(n) | ||
| # # Space Complexity: O(n) | ||
|
|
||
| def bfs(self): |
No description provided.