Skip to content
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
15 changes: 14 additions & 1 deletion graphs/possible_bipartition.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# Can be used for BFS
from collections import deque

def bipartition_helper(counter_list, key, dislikes):
if len(counter_list) % 2 != 0 and counter_list[0] == key:
return False
if key in counter_list:
return True
for value in dislikes[key]:
if bipartition_helper(counter_list + [key], value, dislikes) == False:
return False
return True

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: ?
"""
pass
for key in dislikes.keys():
if bipartition_helper(list(), key, dislikes) == False:
return False
return True