Skip to content

Flood fill fills diagonally & errors if edges are to be filled #2836

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

Closed
appgurueu opened this issue Nov 21, 2021 · 7 comments
Closed

Flood fill fills diagonally & errors if edges are to be filled #2836

appgurueu opened this issue Nov 21, 2021 · 7 comments

Comments

@appgurueu
Copy link

1f17076
It:

  1. Fills diagonally, which isn't how flood fill usually works;
  2. Lacks a check for x < width && y < height: I assume it crashes if that happens (with an AIOOB Ex.)
@siriak
Copy link
Member

siriak commented Nov 22, 2021

IMO filling diagonally is fine, it's one of the ways it can be implemented. As for the check, could you fix that and maybe add a test for that?

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 23, 2021
@appgurueu
Copy link
Author

What the heck, issues don't resolve themselves. The bot should be disabled.

@nikslyon19
Copy link
Contributor

Should this not be categorised as a Backtracking problem, rather than dynamic programming?

@appgurueu
Copy link
Author

Should this not be categorised as a Backtracking problem, rather than dynamic programming?

Flood fill is indeed often categorized as backtracing. That's a different issue though: This issue is about a possible crash in the implementation.

@nikslyon19
Copy link
Contributor

Flood fill is indeed often categorized as backtracing. That's a different issue though: This issue is about a possible crash in the implementation.

Agreed. The corner case is not covered for the function going beyond the dimensions of the 2D array.
In the example given in the code, if you were to replace '3' with '1' at any of the right/bottom most position where it is adjacent to '1', you will get index out of bounds exception.

@nikslyon19
Copy link
Contributor

IMO filling diagonally is fine, it's one of the ways it can be implemented. As for the check, could you fix that and maybe add a test for that?

Since this issue is still unresolved for months, would be happy to take over this one.

Would be covering the missing corner case, add a few test cases (asserts I believe?), and if it's okay, would like to move this code under the backtracking directory/category.

nikslyon19 added a commit to nikslyon19/Java that referenced this issue Mar 9, 2022
@nikslyon19 nikslyon19 mentioned this issue Mar 9, 2022
8 tasks
nikslyon19 added a commit to nikslyon19/Java that referenced this issue Mar 11, 2022
@siriak siriak closed this as completed in 260a302 Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants