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

Maple - Christine #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/Bipartition-Graph.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 46 additions & 3 deletions graphs/possible_bipartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,51 @@ 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)
Space Complexity: O(N)
"""
Comment on lines +8 to 10

Choose a reason for hiding this comment

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

pass

if not dislikes:
return True

queue = deque()
dogs = set()
group_1 = set()
group_2 = set()

if dislikes[0]:
start = 0
else:
start = 1
Comment on lines +20 to +23

Choose a reason for hiding this comment

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

Consider an edge case where dislikes has multiple nodes at the beginning of the list that are disconnected from the graph. How might your refactor your code to address this edge case?


queue.append(start)
dogs.add(start)
group_1.add(start)

while len(queue):

Choose a reason for hiding this comment

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

🦴 Very nice BFS implementation!

current = queue.popleft()

for disliked_dog in dislikes[current]:
if disliked_dog not in dogs:
dogs.add(disliked_dog)
queue.append(disliked_dog)
if current in group_1:
group_2.add(disliked_dog)
else:
group_1.add(disliked_dog)
elif disliked_dog in dogs:
if current in group_1 and disliked_dog in group_1:
return False
elif current in group_2 and disliked_dog in group_2:
return False

return True