During the [[Rasterraster scan|Raster Scan]] of the grid, whenever an occupied cell is encountered, neighboring cells are scanned to check whether any of them have already been scanned. If we find already scanned neighbors, the <code>union</code> operation is performed, to specify that these neighboring cells are in fact members of the same equivalence class. Then the<code>find</code> 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 entire grid is processed in this way.