-
Notifications
You must be signed in to change notification settings - Fork 44
Leah - Space #27
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?
Leah - Space #27
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.
Very nice work, you even got the Breadth-first-search and did many of the traversals with loops. Well done.
# Time Complexity: Olog(n) - only need to look at half the tree | ||
# Space Complexity: O(1) | ||
def add(key, value) |
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.
👍 Since you're doing this recursively, the space complexity is O(log n) if the tree is balanced and O(n) if it is unbalanced. Same for time complexities.
# Time Complexity: Olog(n) - only need to look at half the tree | ||
# Space Complexity: O(1) | ||
def find(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 Complexity: O(n) - n is the number of nodes in the tree | ||
# Space Complexity: O(n) - my thought is that since we're making a list of nodes to return, we'll have that many nodes stored in the list, but since the stack doesn't ever hold something that's also already in the list, there would never be more than n nodes stored at one time..? Let me know if that's on the right track. | ||
# left, root, right (me btwn my children) | ||
def inorder |
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 doing this with loops and a stack. I guess you REALLY don't like recursion.
# Time Complexity: O(n) - n is the number of nodes in the tree | ||
# Space Complexity: O(n) - same assumption as inorder | ||
# root, left, right (me before my children) | ||
def preorder |
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(n) - n is the number of nodes in the tree | ||
# Space Complexity: O(n) - same assumption as inorder | ||
# left, right, root (me after my children) | ||
def postorder |
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: Olog(n) in the best case (e.g. if the tree is balanced), O(n) in the worst case (the tree is unbalanced and essentially a linked list) | ||
# Space Complexity: O(1) | ||
def height |
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.
👍 , Since you are doing this recursively the space complexity is O(log n) if the tree is balanced and O(n) otherwise.
# Time Complexity: O(n) - n is number of nodes | ||
# Space Complexity: O(n) - queue will hold at most the entire tree | ||
def bfs |
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!
No description provided.