Velocity Reviews > Compare data in two groups

# Compare data in two groups

Davy
Guest
Posts: n/a

 07-22-2005
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
Guest
Posts: n/a

 07-22-2005
Davy wrote:
> 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

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

Keith Thompson
Guest
Posts: n/a

 07-22-2005
"Davy" <> writes:
> 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.

When you re-post this question to a more appropriate newsgroup, like
comp.programming, 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_Keith) kst- <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.

Emmanuel Delahaye
Guest
Posts: n/a

 07-23-2005
Davy wrote on 22/07/05 :
> 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?

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?"