11-20-2015 06:01 AM
Hi
I have got two large array of strings. I would like to compare both of them with each other and extract the string which isnt available in both of the arrays.
Which is the best method to implement this.?
Thanks in advance.
11-20-2015 06:25 AM - edited 11-20-2015 06:26 AM
11-20-2015 06:42 AM - edited 11-20-2015 06:44 AM
HI Gerd,
Here is the example what I am trying to implement .. below you find the attachment of my VI.
11-20-2015 07:01 AM
Hi Reddy,
please take some tutorials - they are for free!
Learn about
- autoindexing tunnels at loop borders
- wiring case structures correctly to avoid "default if unwired" output tunnels
Then you should learn to analyze your problem and to formulate the solution with words/diagrams/pseudocode:
output := [] FOREACH element in Array1 search element in Array2 IF found THEN do nothing ELSE add element to output ENDIF NEXT
This pseudocode will not solve your problem in total, but should give you a good start!
11-20-2015 07:56 AM
You said your arrays are large. Large is a relative term, but this often requires different kinds of optimizations, depending on what your goals are. I won't go into the different options because of that, but here's one which relatively efficient, also in psuedo code:
ForEach N in A[]
SetVariantAttribute(N)=GetVariantAttribute(N) OR 1
ForEach N in B[]
SetVariantAttribute(N)=GetVariantAttribute(N) OR 2
ForEach N in variant
If GetVariantAttribute(N)<3 Then exclusive
The idea is that variant attributes are an efficient way of storing and searching for values and it minimizes the number of times you need to go over elements. You use a byte as the type for the attribute and use bit 1 to indicate it's in A and bit 2 to indicate it's in B. This will also handle duplicate values as the same. Use a shift register to make sure you use the same variant.
11-20-2015 08:26 AM
Another alternative,
Concatenate the two arrays, then:
For each element in array search for this element from a copy of this array with the current element deleted (if the original element is at index 4 of the array the delete element at index 4 from the copy of the array and search the resulting array with subset deleted for this element) . If found then the element is not unique, if not then add to output.
Ben64
11-20-2015 10:48 AM
Or
"Concatenate the two arrays, then:" download the OpenG toolkit from the LabVIEW tools network and use the 'Remove duplicates from 1D array.vi'.
11-20-2015 11:03 AM
@GovBob wrote:
Or
"Concatenate the two arrays, then:" download the OpenG toolkit from the LabVIEW tools network and use the 'Remove duplicates from 1D array.vi'.
That won't work, an element that is present in both array will still be present at the output (only the duplicate is removed). What we want at the output are elements that doesn't have a duplicate.
Ben64
11-20-2015 11:07 AM
Oops, I misread the question. I'm sure glad it's friday.
11-20-2015 11:15 AM - edited 11-20-2015 11:33 AM
@mkReddy wrote:
I have got two large array of strings. I would like to compare both of them with each other and extract the string which isnt available in both of the arrays.
Ok, there are probably better ways to describe the problem. Basically you want a 1D array containing all elements that only exist in one of the two input arrays, right?
If an element occurs more than once in a single array, do you want to have it more than once in the output?
Why do your arrays contain so many extra empty strings at the end?
All you need is FOR loops, some search logic, and a conditional output tunnel. If you sort the two arrays first, you don't need to search the second array from the beginning, improving performance.