Compare data in two groups

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Davy

    #1

    Compare data in two groups

    Hello all,

    I have two groups of digit data. The data in it may be repeated.
    Some thing like {5 59 74 17 5 1} and {3 8 25 4}. And real group is
    larger. Each may own thousands of data.
    I want to write a program to compare the two groups.

    //------program--------
    IF (one data in Group 1 == one data in Group 2)
    EXIT the program.

    Is there any quick compare algorithm?

    Best regards,
    Davy

  • David Resnick

    #2
    Re: Compare data in two groups

    Davy wrote:[color=blue]
    > Hello all,
    >
    > I have two groups of digit data. The data in it may be repeated.
    > Some thing like {5 59 74 17 5 1} and {3 8 25 4}. And real group is
    > larger. Each may own thousands of data.
    > I want to write a program to compare the two groups.
    >
    > //------program--------
    > IF (one data in Group 1 == one data in Group 2)
    > EXIT the program.
    >
    > Is there any quick compare algorithm?
    >
    > Best regards,
    > Davy[/color]

    Nothing about this is specific to C, and comp.programmin g is likely
    a better place for general algorithm questions.

    Some random ideas to ponder (no promises of efficiency).

    1) Sort one data set and then use binary search for each member of the
    other set.

    2) Hash one data set (make a hashtable) and look up each member of
    the other set

    3) Sort both sets, iterate through both comparing as you go (not hard)

    4) If you are not stuck on using C, you could use C++ sets and get
    the intersection (if you want this, go to comp.lang.c++ to discuss)

    -David

    Comment

    • Keith Thompson

      #3
      Re: Compare data in two groups

      "Davy" <zhushenli@gmai l.com> writes:[color=blue]
      > I have two groups of digit data. The data in it may be repeated.
      > Some thing like {5 59 74 17 5 1} and {3 8 25 4}. And real group is
      > larger. Each may own thousands of data.
      > I want to write a program to compare the two groups.[/color]

      When you re-post this question to a more appropriate newsgroup, like
      comp.programmin g, you might want to define the problem better. I can
      guess what you mean by "compare", but I can't be sure.

      Rigorously and unambiguously defining the problem may get you much of
      the way to a solution.

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
      We must do something. This is something. Therefore, we must do this.

      Comment

      • Emmanuel Delahaye

        #4
        Re: Compare data in two groups

        Davy wrote on 22/07/05 :[color=blue]
        > I have two groups of digit data. The data in it may be repeated.
        > Some thing like {5 59 74 17 5 1} and {3 8 25 4}. And real group is
        > larger. Each may own thousands of data.
        > I want to write a program to compare the two groups.
        >
        > //------program--------
        > IF (one data in Group 1 == one data in Group 2)
        > EXIT the program.
        >
        > Is there any quick compare algorithm?[/color]

        Yes, based on:

        qsort()
        bsearch()
        loops...

        Be smart.

        --
        Emmanuel
        The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
        The C-library: http://www.dinkumware.com/refxc.html

        I once asked an expert COBOL programmer, how to
        declare local variables in COBOL, the reply was:
        "what is a local variable?"


        Comment

        Working...