Reputation: 147
I am looking for an efficient algorithm to synchronize two arrays. Let's say a1 and a2 are two arrays given as input.
a1 - C , C++ , Java , C# , Perl
a2 - C++ , Python , Java , Cw , Haskel
Output 2 arrays:
Output A1: C , C++ , Java
Output A2: Cw , Haskell , Python
Output A1:
1) items common to both arrays 2) items only in A1 and not in A2
Output A2:
items only in a2
Thanks in advance.
Raj
Upvotes: 1
Views: 3008
Reputation: 19938
Do this until you processed all elements in the sorted arrays, complexity of O(n).
Upvotes: 7