Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Finding duplicates

Finding duplicates

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RChin
    wrote on last edited by
    #1

    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

    Steve EcholsS 1 Reply Last reply
    0
    • R RChin

      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

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      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!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      R 1 Reply Last reply
      0
      • Steve EcholsS Steve Echols

        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!

        R Offline
        R Offline
        RChin
        wrote on last edited by
        #3

        Thanks. I'll do a quick sample test project to check the speed between the two methods. The std::set insertion technique works fine (just finished the coding), but I suspect that it is not the fastest way of doing this.


        I Dream of Absolute Zero

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups