Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
✨🌟 Nice work, Angela. I left some comments on time and space complexity as well as how you might rework your BFS implementation. Let me know what questions you have.
🟢
| # Time Complexity: | ||
| # Space Complexity: | ||
| # Time Complexity: O(log n) | ||
| # Space Complexity: O(log n) |
There was a problem hiding this comment.
🪐 Space complexity will be O(1) here because you aren't creating a call stack or any new data structures that vary with the size of the input (the size of your tree)
| # Time Complexity: | ||
| # Space Complexity: | ||
| # Time Complexity: O(log n) | ||
| # Space Complexity: O(log n) |
There was a problem hiding this comment.
🪐⬆️ Same thing as add with the space complexity here
|
|
||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def inorder(self): |
|
|
||
| # Time Complexity: O(log n) | ||
| # Space Complexity: O(log n) | ||
| def preorder(self): |
|
|
||
| # Time Complexity: O(log n) | ||
| # Space Complexity: O(log n) | ||
| def postorder(self): |
There was a problem hiding this comment.
⏱🪐 This is going to be O(n) space complexity like preorder and inorder because you are creating a list of all n nodes in the tree and to do that you are creating a recursive call for each of the n nodes.
| # Time Complexity: O(log n) | ||
| # Space Complexity: O(log n) |
There was a problem hiding this comment.
⏱🪐 Time and space complexity is going to be O(log n) because you recursively call height_helper on each node in the list.
| # # Space Complexity: | ||
| # # Time Complexity: O(n) | ||
| # # Space Complexity: O(n) | ||
| def bfs(self): |
There was a problem hiding this comment.
With breadth first search you want to traverse the tree starting from its root, then visit each of it's children (from left to right), before visiting the children's children and so forth. In other words, you want to traverse the tree level by level.
With your bfs_helper, you are adding the root node of the current tree, but then your recursive call through the left subtree will finish before you ever look at the root of the right subtree.
(Hint: this may be easier to think about iteratively)
No description provided.