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

Cedar - Laurel S. #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paperbackwriter2
Copy link

No description provided.

Copy link

@kyra-patton kyra-patton left a comment

Choose a reason for hiding this comment

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

🐾🐶 Nice BFS solution, Laurel. I left a few comments and suggestions below. Let me know what questions you have.

🟢


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 * m) where n is the number of nodes/dogs

Choose a reason for hiding this comment

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

⏱ Time complexity will actually be O(n + m) because you traverse each node and each edge exactly once. O(n*m) would mean that you traverse all the edges in the entire graph for each node in the graph.

Space Complexity: ?
Time Complexity: O(n * m) where n is the number of nodes/dogs
and m is the number of edges
Space Complexity: O(n)

Choose a reason for hiding this comment

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

Comment on lines +13 to +21
def createGraph(nodes):
graph = {}
for index, edge in enumerate(nodes):
graph[index] = []
for neighbor in edge:
graph[index].append(neighbor)
return graph

graph = createGraph(dislikes)

Choose a reason for hiding this comment

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

Totally fine to do this, I just want to note that dislikes is already considered an adjacency list. Adjacency lists can be represented as either a list of lists where the nodes are represented by the indices and the edges are the values(which is what we provide), or as a dictionary where the nodes are the keys and the values are the edges.

Comment on lines +31 to +32
if group == visited[dog]:
continue

Choose a reason for hiding this comment

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

Is there a way you might refactor your code to eliminate the continue statement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants