Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9266367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:18:06+00:00 2026-06-18T14:18:06+00:00

I need to find holes in a 2D grid in java – can you

  • 0

I need to find “holes” in a 2D grid in java – can you point me toward the best sort of algorithm to do this?

With the input of the following points:

5,3
5,4
8,4
5,5
6,3
7,3
7,4
6,5

I need to figure out the positions of the “hole” or surrounded space in this grid. I’m a bit lost as to how to do this.

Plot of the points:

enter image description here

Assuming each point is 1×1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:18:08+00:00Added an answer on June 18, 2026 at 2:18 pm

    This is basically a blob extraction algorithm + a bit extra. Do this:

    1) Find the westmost, eastmost, northmost and southmost any solid is placed. Remember them as xmin xmax ymin ymax.

    2) Allocate an 2d array of integers (initialized to 0) with those dimensions, and place all solid points in it as the value -1.

    3) Make a counter initialized to 1. Scan the 2d array. Every time you find a point that is 0, set it to counter and floodfill counters onto every adjacent point that is not a -1 until you’ve run out of points to floodfill onto. (To do a floodfill, one way is to keep a set of all points you haven’t floodfilled all the neighbours of yet, and iterate over these, adding new points to the set until the set is exhausted -> nothing left to floodfill onto.) Now increment the counter and continue.

    4) When you’ve scanned the whole grid, scan the perimeter. Every time you see a non -1 on the perimeter, mark that blob as not being surrounded (by having an array of bools as long as the number of blobs you found).

    5) Every numbered blob you have not marked is surrounded.

    Read about blob extraction here: http://en.wikipedia.org/wiki/Blob_extraction

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to create a 3D grid? In java, I am
I have as an input a 2D polygon with holes, and I need to
This is an Oracle question. I need to find the top 5 biggest values
Need to find the timestamp for the first minute of the first day of
I need to find a flexible solution for access control in PHP. In the
i need to find out automationid for key board values? how to send keystrokes
I need to find all the occurences of a file Test.TXT in c:\ or
I need to find the coordinates of windows open even when they are not
I need to find a silence in a mp3 file. Simple as that. For
I need to find out the value passed into an indexer. My code (c#)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.