-
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
Cedar - Laurel S. #35
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.
🐾🐶 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 |
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.
⏱ 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) |
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.
✨
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) |
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.
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.
if group == visited[dog]: | ||
continue |
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.
Is there a way you might refactor your code to eliminate the continue
statement?
No description provided.