-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: master
Are you sure you want to change the base?
FIRE - Tram #3
Conversation
There was a problem hiding this 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.
# 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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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.
No description provided.