473,322 Members | 1,703 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,322 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 1629
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.