Open
Conversation
CheezItMan
reviewed
Sep 2, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
Very nice work, you even got the Breadth-first-search and did many of the traversals with loops. Well done.
Comment on lines
+19
to
21
| # 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.
👍 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.
Comment on lines
+43
to
45
| # Time Complexity: Olog(n) - only need to look at half the tree | ||
| # Space Complexity: O(1) | ||
| def find(key) |
Comment on lines
+61
to
64
| # 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.
Nice work doing this with loops and a stack. I guess you REALLY don't like recursion.
Comment on lines
+92
to
+95
| # 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 |
Comment on lines
+112
to
+115
| # 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 |
Comment on lines
+139
to
141
| # 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.
👍 , Since you are doing this recursively the space complexity is O(log n) if the tree is balanced and O(n) otherwise.
Comment on lines
+156
to
158
| # Time Complexity: O(n) - n is number of nodes | ||
| # Space Complexity: O(n) - queue will hold at most the entire tree | ||
| def bfs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.