Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a situation as below

C#
string[] A = {'a','x','ab','z','c','d'}
string[] B = {'a','ab','c','xz','d'}


I need to write search method for searching elements in A in B. It should search every element in A with elements in B, and also with combination of elements in A.
Eg : 'a' present in B
'xz' present in B

What searching process i can use for this to finish in minimum iterations. Please suggest.

Thanks
Posted
Updated 20-Nov-14 23:16pm
v3
Comments
Thanks7872 21-Nov-14 5:20am    
What have you tried till now?
Mada Naga Sankar 21-Nov-14 5:23am    
I have tried with for loops, taking each element in A, concatenating with all other elements in A and searching in B. but its taking more iterations. Is there any better approach.

Firstly, decide what language you want to use: you have tagged this with every language you could find, and the solutions will be different for each. Since your code sample is C#, just tag it with that.

Second, we do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
I create an simple example for search one array in another--

using System;
using System.Linq;

namespace ArrayComparison
{
class Program
{
static void Main(string[] args)
{

string[] A = { "a", "x", "ab", "z", "c", "d" };
string[] B = { "a", "ab", "c", "xz", "d" };

foreach (var x in A)
{
if(B.Contains(x))
{
Console.WriteLine(x);
}
}
Console.ReadLine();

}
}
}


But you mentioned that "
Quote:
also with combination of elements in A.
"
So could you please explain this in more detail so I could create accordingly.
 
Share this answer
 
Comments
Mada Naga Sankar 21-Nov-14 5:56am    
This search works with each individual elements in A. i need to search with elements like
'ax','aab','az','ac','ad'..
'axab','axz'..
All possible combinations of elements in A. Is there any easy way for this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900