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

Space - Chelsea #20

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

Space - Chelsea #20

wants to merge 3 commits into from

Conversation

ChelseaC13
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.

Well done Chelsea, you hit all the requirements. Nice work!

Comment on lines +20 to 22
# 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)

Choose a reason for hiding this comment

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

👍

Comment on lines +53 to 55
# 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)

Choose a reason for hiding this comment

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

👍

Comment on lines +78 to 80
# 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

Choose a reason for hiding this comment

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

👍

Comment on lines +102 to 104
# 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

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)

Comment on lines +126 to 128
# 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

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.

Comment on lines +151 to 153
# 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

Choose a reason for hiding this comment

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

👍

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