I went through the code of r.lake, and found a few relevant things that might speed things up. I am hoping to get some brickbats and suggestions on this one.<br><br>Basic idea is to map the map as a binary image of 0 and 1<br>

Do a connected component labelling of the image<br>Must be faster than regular O(n3) method that is given in the code.<br>The basic Idea I have is of using the temporary map to keep as a union find datastructure, <br><br>
References<br><br><a href="http://en.wikipedia.org/wiki/Connected_Component_Labeling#Two-pass">http://en.wikipedia.org/wiki/Connected_Component_Labeling#Two-pass</a><br><br>page 12 to 14 of <a href="http://www.cse.msu.edu/%7Estockman/Book/2002/Chapters/ch3.pdf" target="_blank">http://www.cse.msu.edu/~stockman/Book/2002/Chapters/ch3.pdf</a><br>

<br>If anybody is intrested, I can give a more detailed description....<br>:)<br><br>-- <br>JYOTHISH SOMAN<br>MS-2008-CS<br>Center for Security, Theory And Algorithm Research (CSTAR)<br>International Institute of Information Technology<br>
Hyderabad<br>India<br>Phone:+91-9966222626<br><a href="http://www.iiit.ac.in/" target="_blank">http://www.iiit.ac.in/</a><br>
--------------------------------------------------------------<br>The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.<br>

    George Bernard Shaw<br>--------------------------------------------------------<br><br>