Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
🐾🐶 Nice BFS solution, Laurel. I left a few comments and suggestions below. Let me know what questions you have.
🟢
| 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.
⏱ 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) |
| 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.
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.
Is there a way you might refactor your code to eliminate the continue statement?
No description provided.