-
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
Scissors laurel O #60
base: master
Are you sure you want to change the base?
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.
I like the consistent naming of the helper methods. Thanks for getting this in Laurel. Take a look at my feedback and let me know if you have questions.
binary_search_tree/tree.py
Outdated
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
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.
👍 However the time complexity is O(n) for an unbalanced tree and O(log n) for a balanced tree.
Also the space complexity is the same due to the call stack (recursion).
# Time Complexity: O(log n) | ||
# Space Complexity: O(1) | ||
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 Complexity: O(n) | ||
# Space Complexity: O(n) | ||
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 Complexity: O(n) | ||
# Space Complexity: O(n) | ||
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.
👍
binary_search_tree/tree.py
Outdated
# Time Complexity: O(n) | ||
# Space Complexity: O(log n) | ||
def height(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.
👍 Space complexity is right if the tree is balanced O(n) otherwise.
binary_search_tree/tree.py
Outdated
# # Time Complexity: O(n) | ||
# # Space Complexity: O(n) | ||
def bfs(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.
👍 However since you're using an array as a queue the queue.pop(0)
is an O(n) operation by itself making your BFS solution O(n^2). You can reduce this by using a deque or a linked list.
No description provided.