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

Raisah #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/possible_bipartition.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@

def possible_bipartition(dislikes)
raise NotImplementedError, "possible_bipartition isn't implemented yet"
return true if dislikes.empty?

i = 0
while dislikes[i].empty?
i += 1
end

stack = []
visited = []
stack.push(i)

until stack.empty?

Choose a reason for hiding this comment

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

You have a depth first search here, but how would this work for a disconnected graph? I think may only be satisfying the tests based on the fact that you're starting with the first node that has a connection.

dog = stack.pop
visited.push(dog)

dislikes[dog].each do |other_dog|
unless visited.include?(other_dog)
stack.push(other_dog)
end
end
end

return visited.length == (dislikes.length - i)
end