How would I write an efficient algorithm to search for a subset array of integers in another array in C? For example:
unsigned a[] = {42, 72, 61, 1023, 84, 42, 42, 193, 302, 72};
unsigned long al = 10;
unsigned b[] = {61, 1023, 84};
unsigned long bl = 3;
I've tried a brute-force approach, by looping through a
and then looping through b
if a[n]
is b[0]
, but then backtracking if the match fails halfway. It seems like the best I can think of, but I'm sure there must be a faster way.