-
Notifications
You must be signed in to change notification settings - Fork 44
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
Space - Chelsea #20
base: master
Are you sure you want to change the base?
Space - Chelsea #20
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.
Well done Chelsea, you hit all the requirements. Nice work!
# Time Complexity: log n because it is binary to find where to add the node | ||
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n) | ||
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.
👍
# Time Complexity: log n due to the binary search | ||
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n) | ||
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) because it has to go through every node. | ||
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n) | ||
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.
👍
# Time Complexity: O(n) because it has to go through every node. | ||
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n) | ||
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.
The space complexity for these traversals is O(n) because we're building an array.
With recursion it would be O(n + n) = O(2n) = O(n) or average case O(n + log n) = O(n)
# Time Complexity: O(n) because it has to go through every node. | ||
# Space Complexity: worst case O(n) because we hit every node, better average case like in a balanced tree it would be O(log n) | ||
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.
👍 With the earlier note on the traversals.
# Time Complexity: O(n) because we hit eery node | ||
# Space Complexity: worst case O(n) because we hit every node better average case like in a balanced tree it would be O(log n) | ||
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.
👍
No description provided.