Skip to content

Morgan - Leaves#34

Closed
morganschuler wants to merge 2 commits intoAda-C12:masterfrom
morganschuler:master
Closed

Morgan - Leaves#34
morganschuler wants to merge 2 commits intoAda-C12:masterfrom
morganschuler:master

Conversation

@morganschuler
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

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

Nice work, you hit the basic learning goals, with some issues on space/time complexity. Check out my comments and let me know if you have any questions.

Comment thread lib/tree.rb
Comment on lines +19 to 21
# Time Complexity: O(log (n))
# Space Complexity: O(log (n))
def add(key, value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/tree.rb
Comment on lines +38 to 40
# Time Complexity: O(n)
# Space Complexity: O(n)
def find(key)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the tree is balanced this is O(log n) for both time & space and O(n) if it's not.

Comment thread lib/tree.rb
Comment on lines +55 to 57
# Time Complexity: o(n)
# Space Complexity: O(n)
def inorder
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/tree.rb
Comment on lines +72 to 74
# Time Complexity: O(n)
# Space Complexity: O(n)
def preorder
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/tree.rb
Comment on lines +89 to 91
# Time Complexity: O(n)
# Space Complexity: O(n)
def postorder
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/tree.rb
Comment on lines +106 to 108
# Time Complexity: O(n)
# Space Complexity: O(n)
def height
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're visiting each node so the time complexity is right, but the space complexity (for a balanced tree) is O(log n ) because your call stack will never get greater than the height of the tree.

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