Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Leah - Space #27

wants to merge 1 commit into from

Conversation

leahwho
Copy link

@leahwho leahwho commented Sep 1, 2020

No description provided.

@leahwho leahwho changed the title methods added and tests passing Leah - Space Sep 1, 2020
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.

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)

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.

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)

Choose a reason for hiding this comment

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

👍

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

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.

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

Choose a reason for hiding this comment

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

👍

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

Choose a reason for hiding this comment

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

👍

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

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.

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

Choose a reason for hiding this comment

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

👍 , nice work!

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