Algorithms: How to Search a Graph with Depth First Search

int[][] rectangles = new int[][] {
{1, 0, 0, 1, 1},
{0, 0, 0, 0, 0},
{0, 1, 1, 0, 0},
{0, 0, 0, 1, 1},
{1, 0, 0, 1, 1},
{0, 0, 0, 0, 0},
{0, 1, 0, 0, 0},
{1, 1, 0, 0, 0}
};
  1. If land (1s) is found, use recursion to investigate all the cells around this land until you encounter 0s
  2. All 1s that are encountered get marked out with 0s. This is so you can keep track of where you have been.
  3. When you finish do something with either the coordinates or land that you have counted.
found coordinates 6

row 0 col 0


row 0 col 3
row 0 col 4


row 2 col 1
row 2 col 2


row 3 col 3
row 3 col 4
row 4 col 4
row 4 col 3


row 4 col 0


row 6 col 1
row 7 col 1
row 7 col 0

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store