I have a sparse matrix that contains several islands of unknown size. I would like to find the highest peak of each islands. Consider this matrix as an example:0 0 1 0 0 0 00 0 1 2 1 0 00 0 0 3 2 1 00 1 0 0 0 0 00 2 3 4 0 1 00 0 1 1 0 1 00 0 0 0 0 1 0In this case I would like to get the position of 3 at (3, 2), the position of 4 at  (3, 4) and the position of 1 at (5, 4), (5, 5) or (5, 6). Note: I consider 4-connected neighbours.Until now I came up with the solution that scans each pixel and if it is not zero it starts a flood fill from that pixel. The flood fill paints the pixels to zero keeping track the maximum value visited. This algorithm works well but I was wondering if there are any faster solution?In my target platform (iOS) I have access to different vector processing frameworks like BLAS, LAPACK, vDSP that provide some functions for fast finding the maximum value in a vector (or matrix). Maybe one could implement a faster solution with the help of these functions?
Find the peak of each islands in sparse matrix
algorithms;data structures;algorithm analysis;matrices