java - Efficiently finding the intersection of a variable number of sets of strings -


I have a variable number of ArrayList for which I need to find the intersection I have a realistic cap on the set of string Maybe around 35, but maybe I do not want any code, just consider that which can be efficient. I have an implementation that I'm about to start coding but want to hear some other ideas.

Currently, just thinking about my solution, it seems that I should have an uncommon run-time Θ (n 2 ).

Thanks for any help!

tshred

EDIT: To clarify, I really want to know that a faster way to do this is faster than Θ (n 2 ) .

This is how you find the intersection of two sets if you type HashSet , Change your from ArrayList to s and using retainAll () in a loop, they all actually O (n)


Comments