Finding duplicates
-
Hey guys. What do you recommend as the quickest method of finding duplicate values in a list of items or array. These item type could be numeric or (in this case) a string. In the past I've used the technique of inserting the items in an stl set. This would immediately flag if you are trying to insert the same item again. But this can get slow if I have a large list of items to wade through. Are there any other techniques that you guys are using?
I Dream of Absolute Zero
-
Hey guys. What do you recommend as the quickest method of finding duplicate values in a list of items or array. These item type could be numeric or (in this case) a string. In the past I've used the technique of inserting the items in an stl set. This would immediately flag if you are trying to insert the same item again. But this can get slow if I have a large list of items to wade through. Are there any other techniques that you guys are using?
I Dream of Absolute Zero
If your list is sorted, you could use a binary search http://en.wikipedia.org/wiki/Binary_search[^]. If not sorted, you'll have to scan the entire list/array for duplicates. Re-creating your list, just to determine if there are duplicates, would not be the most efficient way to do it - just run a loop over the original list/array.
- S 50 cups of coffee and you know it's on!
-
If your list is sorted, you could use a binary search http://en.wikipedia.org/wiki/Binary_search[^]. If not sorted, you'll have to scan the entire list/array for duplicates. Re-creating your list, just to determine if there are duplicates, would not be the most efficient way to do it - just run a loop over the original list/array.
- S 50 cups of coffee and you know it's on!