-
Notifications
You must be signed in to change notification settings - Fork 65
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
C16 - Pine - Ainur #44
base: master
Are you sure you want to change the base?
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.
🐾🐶 Good work, Ainur. I wrote a comment to help point you in the right direction as to why your test cases aren't passing. Let me know what questions you have.
🟡
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: O(N+E) N-number of nodes, E -number of edges | ||
Space Complexity: O(N)?? |
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.
🪐 Yes! Space complexity will be O(N) because the data structures you create, queue
, visited
, group1
, and group2
can each hold at most N nodes (aka dogs).
@@ -5,8 +5,33 @@ def possible_bipartition(dislikes): | |||
""" Will return True or False if the given graph | |||
can be bipartitioned without neighboring nodes put | |||
into the same partition. | |||
Time Complexity: ? | |||
Space Complexity: ? | |||
Time Complexity: O(N+E) N-number of nodes, E -number of edges |
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.
✨
group1 = set() | ||
group2 = set() | ||
|
||
queue.append(0) |
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.
Your two test cases are failing because you need a guard clause to find the first node in the list that is connected to other nodes in the graph.
Say you have a graph such as this:
dislikes = [ [], [2, 3], [1, 3], [1, 2] ]
If you draw out the graph, you will see that Node 0 is disconnected from the rest of the graph - it has no edges. Because it has no edges/neighbors, nothing else will be added to your queue after you pop Node 0 off the queue and you will return True
by default.
No description provided.