CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2007
    Posts
    249

    Angry Where Set and Multiset is mostly required

    Hi,
    In the Associative container group we have map, multimap, set and multiset.
    I can understand why map and multimap is used. But set and multiset makes me think where these containers are useful. We can do the samething by using vector (pushing only unique elements) and sorting them.

    so what is the use of Set and multi set??
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Where Set and Multiset is mostly required

    There is more than one way to skin a cat
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Where Set and Multiset is mostly required

    Basically they have different big-Oh costs for some operations. To keep an often-changing vector sorted all the time, you'd have to do a sort on every insertion----O(n*n*log n) in total. A multiset would only require O(n*log n), since it knows how to insert-in-order cheaply unlike a vector. (Even if you explicitly inserted in order, the vector would still need to shuffle over all the greater elements----O(n*n).)

    Also, a set is pretty much the easiest way to select a bunch of unique elements if the total number of possible elements is not small. (If it were, you could use a bool array to decide if you'd accepted a given element yet.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured