-
Notifications
You must be signed in to change notification settings - Fork 69
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
Asli (Alf) - Spruce - C16 #54
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.
Hi Alf, it looks like you may have looked at Ivette's code for this project. While I do not mind if you turn to outside resources for help, it is difficult for me to give feedback as to your understanding of I believe it may not be your own work. For that reason, I'm grading this as a red - because I cannot assess how well you understand the problem.
At this point, you do not need to resubmit. It will not affect your ability to graduate.
self.root = added | ||
|
||
parent = self.root | ||
while True: |
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.
We generally try to avoid while loops whose conditions can never be Falsey. With while loops, we always want the body of the while loop to be making progress toward the condition being False.
How might you refactor you code to eliminate this? Hint: Look at your find
function
else: | ||
return "something went wrong" |
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.
This isn't necessary
else: | |
return "something went wrong" |
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: 0(log(n)) | ||
# Space Complexity: 0(1) | ||
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.
✨
return nodes | ||
|
||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
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.
✨
return nodes | ||
|
||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
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.
✨
return nodes | ||
|
||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
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.
✨
|
||
# Time Complexity: O(nlog(n)) | ||
# Space Complexity: 0(m) -> m == # of nodes | ||
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.
✨ This time and space complexity is correct for your solution!
You could refactor your code to achieve an O(n) time and space solution. Instead of having height_helper return a list, have it return an integer. When you make a recursive call on the left/right subtree, you know that your height is 1 + the height of the deepest subtree. So you can say that the height is 1 + max(height of left subtree, height of right subtree).
pass | ||
added = TreeNode(key, value) | ||
if not self.root: | ||
self.root = added |
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.
If you do not return after this guard close, you'll enter into an infinite loop
self.root = added | |
self.root = added | |
return added |
No description provided.