Skip to content

Rebeca Muniz #Cedar #45

Open
rebecamuniz wants to merge 1 commit intoAda-C16:masterfrom
rebecamuniz:master
Open

Rebeca Muniz #Cedar #45
rebecamuniz wants to merge 1 commit intoAda-C16:masterfrom
rebecamuniz:master

Conversation

@rebecamuniz
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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.

🐾🐶 Hi Rebeca, it looks like you do have some understanding of breadth first search and graphs, however I think you misunderstood what dislikes represented so you're implementation doesn't work for the specification provided. See my review for full details. Feel free to reach out if you have questions and want to talk this over.

🔴

self.graph = [[0 for column in range(V)] \
for row in range(V)]

def possible_bipartition(self, dislikes):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your code won't run in part because this line is indented incorrectly. If you intend this to be a method of your class Graph, you need to tab it over one level.

I think you may be slightly confused about what dislikes represents. dislikes is an adjacency list where the index of each element of the list represents a node, and where the elements are lists containing neighbors (or edges) of the node at that index.

For example in dislikes is the following:
[ [], [2, 3], [1, 4], [1], [2] ]

Then Node 0 (aka dog 0) has no neighbors/edges. Node 1 has neighbors 2 and 3 (meaning dog 1 dislikes dogs 2 and 3), Node 2 has neighbors 1 and 4, and so forth.

This should be sufficient for you to complete the problem. While you can create a Graph class, it shouldn't be necessary.

Time Complexity: ?
Space Complexity: ?
Time Complexity: O(N+E)
Space Complexity: O(N)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✨ Your time and space complexity are correct for a BFS implementation

colorArr = [-1] * self.V

# Assign first color to source
colorArr[dislikes] = 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, dislikes is an adjacency list - a list of lists - so you're trying to index an array with a list here.


# Run while there are vertices in queue
# (Similar to BFS)
while queue:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your approach looks largely correct for an adjacency matrix, but I may be missing something without the tests

Comment on lines +6 to +8
self.V = V
self.graph = [[0 for column in range(V)] \
for row in range(V)]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤔 It looks like you're creating a graph here as an adjacency matrix with no edges initially.

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