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

Lety Palomo -Pine C-16 Graphs #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion graphs/possible_bipartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,21 @@ def possible_bipartition(dislikes):
Time Complexity: ?
Space Complexity: ?

Choose a reason for hiding this comment

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

⏱🪐 Time and space complexity?

"""
pass
grouped = {}
dog_q=deque()
for i in range (len(dislikes)):
if i not in grouped:
dog_q += [i]

Choose a reason for hiding this comment

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

🤔 I'm not exactly sure why you are adding i as a list to the queue. It should be sufficient to just add i

grouped[i]=0

while dog_q:
dog_node = dog_q.popleft()
for neighbor in dislikes[dog_node]:
if neighbor not in grouped:
dog_q += [neighbor]
grouped[neighbor] = grouped[dog_node] ^ 1
elif grouped[neighbor] == grouped[dog_node]:
return False
return True