[1] The algorithm was originally described by Joseph Hoshen and Raoul Kopelman in their 1976 paper "Percolation and Cluster Distribution.
Neighbors are defined as cells having a common side but not those sharing only a corner i.e. we consider the 4-connected neighborhood that is top, bottom, left and right.
Then thefind operation is performed to find a representative member of that equivalence class with which the current cell will be labeled.
On the other hand, if the current cell has no neighbors, it is assigned a new, previously unused, label.
The dark cells in the grid in figure (a) represent that they are occupied and the white ones are empty.
So by running H–K algorithm on this input we would get the output as shown in figure (b) with all the clusters labeled.