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

BFS Graph Matrix bug? #65

Open
katayamahide opened this issue Dec 4, 2023 · 0 comments
Open

BFS Graph Matrix bug? #65

katayamahide opened this issue Dec 4, 2023 · 0 comments

Comments

@katayamahide
Copy link

Hi @ThePrimeagen and folks,

I really appreciate your passionable cource.
By the way, I may found a bug in BFS Graph Matrix.
As for the BFSGraphMatrix function bfs, if arguments of source and needle are same number, it returns null. But I think it should return the exact number in array.

I mean for example,

// src/day1/DFSGraphList.ts
bfs(matrix, 1, 1)) // expected output  [1], but got null;

To solve this bug, I think the code should be modified like below.

- if (prev[needle] === -1) {
-     return null;
- }

+ if (prev[needle] === -1 && source !== needle) {
+    return null;
+}

Also the test like below should be added .

// src/__tests__/BFSGraphMatrix.ts
expect(bfs(matrix2, 0, 0)).toEqual([0]);
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

No branches or pull requests

1 participant