Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Abigail C - Rock #53

wants to merge 1 commit into from

Conversation

ChaAbby
Copy link

@ChaAbby ChaAbby commented Jan 13, 2022

No description provided.

Copy link

@CheezItMan CheezItMan left a 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.

Comment on lines 17 to 19
# Time Complexity:
# Space Complexity:
def add(self, key, value = None):

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:

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.

Comment on lines 43 to 45
# Time Complexity:
# Space Complexity:
def find(self, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 time/space complexity?

Comment on lines 56 to 58
# Time Complexity:
# Space Complexity:
def inorder(self):

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

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.

Comment on lines 72 to 74
# Time Complexity:
# Space Complexity:
def preorder(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Time/space complexity?

Comment on lines 86 to 88
# Time Complexity:
# Space Complexity:
def postorder(self):

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)

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.

https://www.geeksforgeeks.org/deque-in-python/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants