473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Nov 15 '05 #1
3 1631
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


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

Nov 15 '05 #2
"Davy" <zh*******@gmail.com> 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) ks***@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.
Nov 15 '05 #3
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?"
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Neil | last post by:
Folks, I've got a problem at work, and I'm hoping that someone out there may have had something similar (although I doubt it!) or may be able to offer some advice. I'm in the process of...
1
by: Davy | last post by:
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...
4
by: Nick B | last post by:
Help! :{ I have a simple select query in an Access database that has three parameters. Two are text, one is a date. If I run my query in Access, it prompts for the date, and two text parameters,...
1
by: Simon Gare | last post by:
Hi I need to compare a dynamic field in an asp page to a field in another table, if there is no match then i would like to chane the row colour ( see code below). The problem Im having is...
1
by: TOI DAY | last post by:
Hi All, This is what I want to do. Support I have two file name abc.txt, xyz.txt I did created md5 hash for abc.txt and store it some directory Here is how I create md5 for the abc.txt ...
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
10
by: ljh | last post by:
Google ran dry on me while looking for .Net examples of how to compare 2 Word Docs. Has anyone here seen anything like that?
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
4
by: Google Groups | last post by:
If i take two structures with same members then,why cann't i compare those two structures?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.