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

Savannah #18

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

Savannah #18

wants to merge 3 commits into from

Conversation

qqdipps
Copy link

@qqdipps qqdipps commented Sep 5, 2019

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, you hit the learning goals here. Do look at my comments on Big-O. I liked the helper methods you wrote and how you did the height methods. Great work!

# Time Complexity:
# Space Complexity:
# Time Complexity: O(log(n)) where n is the number of nodes
# Space Complexity: O(1)

Choose a reason for hiding this comment

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

Remember since you're doing this recursively, the system stack will allocate space for each recursive call.

So if the tree is balanced the space complexity is O(log n), if it's widely unbalanced O(n). The same also applies to time complexity.

return 0 if !node
right = longest_tree_path(node.right)
left = longest_tree_path(node.left)
return [right, left].max + 1

Choose a reason for hiding this comment

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

clever!

# Time Complexity:
# Space Complexity:
# Time Complexity: O(n) where n is the number of nodes
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

The space complexity will be O(n) if the tree is unbalanced (due to the system stack) or O(log n) if the tree is balanced.

# Time Complexity:
# Space Complexity:
# Time Complexity: O(n) where n is the number of nodes
# Space Complexity: O(n) ""
def bfs

Choose a reason for hiding this comment

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

Niiiice!

@@ -69,6 +68,21 @@
end
end

describe "hieght" do

Choose a reason for hiding this comment

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

Nice, I will use these for C12, if that's ok.

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