-
Notifications
You must be signed in to change notification settings - Fork 64
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
Abigail C - Rock #53
base: master
Are you sure you want to change the base?
Abigail C - Rock #53
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.
Nice work Abigail, I added some feedback for minor improvements. Let me know if you have questions.
# Time Complexity: | ||
# Space Complexity: | ||
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.
👍 Time/space complexity?
self.root = TreeNode(key,value) | ||
current = 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.
Just a personal note. I dislike while True
loops which depend on break
statements to control the flow of execution because it makes the loop harder to trace and understand.
# Time Complexity: | ||
# Space Complexity: | ||
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.
👍 time/space complexity?
# Time Complexity: | ||
# Space Complexity: | ||
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.
👍 time/space complexity?
left_part= helper(node.left) | ||
middle_part = [{"key":node.key,"value":node.value}] | ||
right_part = helper(node.right) | ||
result = left_part + middle_part + right_part |
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.
Just a note that doing so much array concatenation is expensive rather than concatenating to the same area each time.
# Time Complexity: | ||
# Space Complexity: | ||
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.
👍 Time/space complexity?
# Time Complexity: | ||
# Space Complexity: | ||
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/space complexity?
|
||
queue.append(self.root) | ||
while queue != []: | ||
temp = queue.pop(0) |
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.
Just a note that queue.pop(0)
is an O(n) operation. Python does have a deque
data structure which provides a similar O(1) operation.
No description provided.