I read through some of the posts about determining whether a set A is a subset of another set B. But I find it hard to determine what algorithm to use. Here is an outline of the problem:
- I have an array of strings
Awhich I receive at the beginning of my program. Not much is known about the structure. Each string in the array can be arbitrarily long and the number of entries is not limited. Though usually it can be assumed that the number of entries in the array won't be overly large (< 100). - Then I iterate through a list of objects of length
n. - Each of the
nobjects will also have an array of stringsB, i.e. there will benBarrays. Once the program runs theBs will be fixed, i.e. they do not change during runtime. - I want to determine for each object if
Ais a subset ofB.
Now, I thought about hashtables. However, they would, in my opinion only be efficient if the was only one B and a lot of As. Then I could make a hashtable for B and check each string array of each object against my hashtable. But this is not the case because there is only one A but n Bs. What would be an efficient algorithm to do this?
Example:
A: ["A", "G", "T"]
B1: ["C", "G"]
B2: ["K", "A", "U", "T", "G"]
.
.
.
Bn: ["T", "I", "G", "O", "L"]
Here A is a subset of B2 but not of B1, and not of Bn.
Ais fixed at the beginning. TheBare also fixed during the runtime of the program. They do not change. But there are a lot ofBs.