Himanshu Gupta wrote:In case it does not contain any duplicates then it will take a long time to make BST representing each file.
Well, "long time" is all relative. If we're counting developer time, I bet we'd get decent results just using whatever sorting tools a given developer is already familiar with (like maybe "cat usernamefile | sort", for the Unix-inclined), sorting both lists of names, waiting for the result, and then using the algorithm Fred outlined to find out what's common to both lists.