Results 1 to 7 of 7

Thread: computing unions of sets

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    computing unions of sets

    I'm having a hard time designing an algorithm to compute a union of a bunch of sets on closed intervals.
    For example if you have sets like these:
    [5,10] [2.2,3] [1,2] [3.1,7] [1.5,2.5], the algorithm should return [1,3] [3.1,10].

    Also how would you merge x number of linked lists (already sorted) into one (also sorted) linked list.

    In both cases I'm looking for as efficient design as possible.

    Thanks
    Q

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    go to the top

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Your question isa total mess (at least it looks this way to me):
    you say you need "...to compute a union of a bunch of sets ..." but your sample shows me that you need to select HIGHER bumbers.
    Also, what do you mean by saying: "... how would you merge x number of linked lists ..."? Be more specific, please.
    Roy

  4. #4
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111


    Better switch to decaf.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    merge two linked lists (or any number for that matter):
    lets say that you have two linked lists (I assume that you know about that data type).
    List 1: (1, 3, 5, 7, 9, 11, 13)
    List 2: (2, 4, 6, 8, 10, 12, 14)
    I need to be able to come up with a new list that looks like this:
    (1,2,3,4,5,6,7,8,9,10,11,12,13,14).
    I know that I could just do it by comparing the numbers one by one, but I need to come up with something way more efficient.

    Second thing: that's exactly what the union of the bunch of sets would look like (UNION of A B C: elements that are in A + Elements that are in B + elements that are in C).

    Thanks
    Q

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Loop through the set, then instr to check a string, then add numbers like num & ","

    if you want it in an array you can then split it.

  7. #7
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    You will have to first merge two lists (arrays) into ONE and then SORT it. For more help on sorting check out this link:
    http://www.vb-helper.com/tut1.htm
    Roy

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