Question: How to separate and count clusters ( 4 direction connected components) in a 2D array? Javascript code example would be great. Thanks! Color version: For

How to separate and count clusters ( 4 direction connected components) in a 2D array? Javascript code example would be great. Thanks! How to separate and count clusters ( 4 direction connected components) in

Color version:

a 2D array? Javascript code example would be great. Thanks! Color version:

For example, I have 2d array like this: And I want to label the connected components (4 directions)to be like this: the way to label the clusters is like the flood fill, if it connects to their neighbor by up-down-left-right direction, they will be grouping in the same cluster, we go from top left to bottom right. Please help me solve this problem. Thanks!!!(javascript code example would be great) Input File 21, 20, 18, 16, 12, 6, 1 Submission Output 1 2 2 2 2 1 1 1 1 2 1 1 2 1 1 1 2 1 2 2 1 1 2 1

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!