-
Notifications
You must be signed in to change notification settings - Fork 62
M. Nguyen - BST #33
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?
M. Nguyen - BST #33
Conversation
CheezItMan
left a comment
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 Melissa, you hit the learning goals here. Well done! Take a look at my comments and let me know what questions you have, primarily on space/time complexity.
| # Time Complexity: O(log n) if tree is balanced | ||
| # Space Complexity: O(n) ? | ||
| 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.
👍 The time complexity is O(log n) for a balanced tree and O(n) for an unbalanced one. Space complexity is the same due to the call stack.
| # Time Complexity: O(log n) if tree is balanced | ||
| # 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.
👍 The time complexity is O(log n) for a balanced tree and O(n) for an unbalanced one. Space complexity is O(1) because you have an iterative solution!
| # Time Complexity: O(n) | ||
| # Space Complexity: Dependent on the size/height of tree, O(h) | ||
| def inorder(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.
👍 Because you're building a list of all the nodes, the space complexity is O(n)
| # Time Complexity: O(n) | ||
| # Space Complexity: Dependent on the size/height of tree, O(h) | ||
| def preorder(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.
👍 Because you're building a list of all the nodes, the space complexity is O(n)
| # Time Complexity: O(n) | ||
| # Space Complexity: Dependent on the size/height of tree, O(h) | ||
| def postorder(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.
👍 Because you're building a list of all the nodes, the space complexity is O(n)
| # Time Complexity: O(n) | ||
| # Space Complexity: Dependent on the size/height of tree, O(h) | ||
| 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.
👍 Nicely done!
No description provided.