Compare data in two groups

D

Davy

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
 
D

David Resnick

Davy said:
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

Nothing about this is specific to C, and comp.programming 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
 
K

Keith Thompson

Davy said:
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.
 
E

Emmanuel Delahaye

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,911
Members
47,453
Latest member
MadelinePh

Latest Threads

Top