The matrices already correspond with each other, correct? So a[0]]0]
already should match with b[0][0], right? So if you start sorting,
you'll need to sort both matrices, and not just one column, since the
columns must be kept in their proper relationship with each other, and
since they're enormous, (even with an optimized mergesort), the
sorting itself is a lot of work and time. I definitely wouldn't do
that.
Subtracting as you mention can be used, but a test for equality is no
slower than subtracting and then checking for a zero result.
Matrix checking is very fast, because several elements can be loaded
into the cache at once, and the rest is naturally buffered by the
compiler in RAM, (and then on the disk at least once), so it proceeds
rapidly. (Much faster than a linked list, for example).
I like your overall approach, but I would generalize it across all the
cells:
For each cell in array A[r][c] /* r = row, c = column */
If the cell in array A[r][c] == the cell in array B[r][c]
then print in black: A[r][c], B[r][c].
else
Change print color to red.
print cell's contents.
change print color back to black
end if
end for
You may want to put the unique rows and col's numbers out to a data
file to prevent it just scrolling off the screen and getting lost.
You may discover that you can use flags to prevent the second X
checking of the array's values, but that won't always be possible. I
believe for your situation, there is no "special" algorithmic speed up
(such as using a hash, or sorting it first, etc.), that can help you.
Don't try to be fancy - simplicity is your friend here. The program
will be able to run very fast if you can avoid the tendency to over-
engineer it.
Try to mimic how YOU would do this work, by hand with paper and
pencil. Humans are very lazy and smart at avoiding inefficient work on
simple tasks.
On Jul 15, 2:34 am, Shark <[EMAIL PROTECTED]> wrote:
> Well its more table then its a matrix, the data is represented in row
>
> row example:
> car | manufacture year | engine volume
> Volvo | 1996 2002
> The data arrives as matrix data structure
> What I thought to do:
>
> Run this :
> For each row in first table get the element at [i][0]
> For each row in second table get element at [j][0]
> {
> Are element equal?{
> For each column in row i in first table mark changes between
> j row
> in the second table
> Break second loop;}
>
> If no matching row found , mark entire row i as missing
> }
> Once on matrix1, matrix2
> And then run it on matrix2,matrix1 (in order to find missing rows in
> matrix2)
>
> Also I thought about sorting the matrixes by the rows first element
> and then perform minus operation between the matrixes row by row and
> get the differences matrix
> I am looking for the best and fastest solution because the matrix size
> is enormous
> Thank you
> Sharon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---