Skip to content

Kristy, Branches#35

Open
kristyh32 wants to merge 4 commits into
Ada-C12:masterfrom
kristyh32:master
Open

Kristy, Branches#35
kristyh32 wants to merge 4 commits into
Ada-C12:masterfrom
kristyh32:master

Conversation

@kristyh32

Copy link
Copy Markdown

No description provided.

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

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 -22
# Time Complexity: O(n)
# Space Complexity: O(n)
def add(key, value)
raise NotImplementedError

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The space/time complexity is O(log n) if the tree is balanced and O(n) if it's not.

Comment thread lib/tree.rb
Comment on lines +35 to 37
# Time Complexity: O(log n)
# Space Complexity: O(log 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.

👍

Comment thread lib/tree.rb
Comment on lines +51 to 53
# 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 +67 to 69
# 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 +81 to 83
# 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 +95 to 97
# 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.

Since you're visiting each node, the time complexity is right, but the space complexity is O(log n) for a balanced tree since the call stack never gets greater than 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