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

Amy W #8

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

Amy W #8

wants to merge 2 commits into from

Conversation

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

Nice work, I like the Set solution, and this works and works well. You hit the learning goals here. If you're curious about my solution (more DFS), you can see it here.

Comment on lines +8 to +9
dogz = Set.new()
doggos = Set.new()

Choose a reason for hiding this comment

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

Nice use of a Set.

dogz1.add(i)
doggos.add(i)

return bipartition_helper(i, dislikes, dogz1, doggos1) || bipartition_helper(i, dislikes, dogz, doggos)

Choose a reason for hiding this comment

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

Originally seeing this pair of recursive calls in this method set off alarm bells, but then I traced through and it doesn't actually make many more recursive calls, it's just a little different from my solution. It does however mean you have do the nested if-else blocks below.

I instead assigned the current "color" for the current node and assigned it's neighbors the alternating color, and then continue in a depth-first-search, and I repeat until the stack is empty. If they already have an incompatible color I return false. This results in a bit simpler code.

This does work however and work well.

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