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

Scissors laurel O #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Scissors laurel O #60

wants to merge 4 commits into from

Conversation

lolkinetzky
Copy link

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.

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.

Comment on lines 16 to 18
# Time Complexity: O(n)
# Space Complexity: O(1)
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.

👍 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).

Comment on lines +34 to 36
# Time Complexity: O(log n)
# Space Complexity: O(1)
def find(self, key):

Choose a reason for hiding this comment

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

👍

Comment on lines +49 to 51
# Time Complexity: O(n)
# Space Complexity: O(n)
def inorder(self):

Choose a reason for hiding this comment

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

👍

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

Choose a reason for hiding this comment

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

👍

Comment on lines 118 to 120
# Time Complexity: O(n)
# Space Complexity: O(log n)
def height(self):

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.

Comment on lines 136 to 138
# # Time Complexity: O(n)
# # Space Complexity: O(n)
def bfs(self):

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.

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