Question: Given: char image[][] = { {'*','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ','

Given:

char image[][] = { {'*','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ',' ',' ',' ',' ','*','*',' ',' '}, {' ','*',' ',' ','*','*','*',' ',' ',' '}, {' ','*','*',' ','*',' ','*',' ','*',' '}, {' ','*','*',' ','*','*','*','*','*','*'}, {' ',' ',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ',' ','*','*','*',' ',' ','*',' '}, {' ',' ',' ',' ',' ','*',' ',' ','*',' '} };

Determine the number of organisms in an image (2d array), and label each organism.

Signature: public static int howManyOrganisms(char[][] image)

Description: Given a 2d array of characters, where an asterisk (*) marks a non-empty cell. An organism is defined as all cells connected directly to other cells in the up/down/left/right (not diagonal) directions.

The method signature above is not a recursive method. Instead, it iterates through the image and as soon as it encounters a new organism, it calls a recursive method (that you define) that labels the newly found organism.

Here is what I have so far:

public static int howManyOrganisms(char[][] image){ for(int row = 0; row < image.length; row++){ for(int col = 0; col < image[row].length; col++){ } } }

Then I know I need to have an if the character is an * I need to call the other recursive method, but I am having a hard time understanding what goes in the recursive method.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!