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

FIRE - Tram #3

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

FIRE - Tram #3

wants to merge 3 commits into from

Conversation

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

Well done Tram, I like the BFS implementation here. Well done.

Comment on lines +1 to 4
# Time complexity:O(n) - visiting each node in the graph once, searching in sets is O(1)
# Space complexity: O(n) - the sets can be filled up based on the content of the dislikes
require 'set'
def possible_bipartition(dislikes)

Choose a reason for hiding this comment

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

👍 For time complexity you're also checking every edge for every node so this is O(N + E)

def possible_bipartition(dislikes)
raise NotImplementedError, "possible_bipartition isn't implemented yet"
return true if dislikes.empty?
group_a, group_b, blocked_a, blocked_b = Set.new, Set.new, Set.new, Set.new

Choose a reason for hiding this comment

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

I like the uses of Set

queue = [ 0 ]
queue << 1 if dislikes[0].empty?

until queue.empty?

Choose a reason for hiding this comment

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

This is a good BFS implementation.

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