I have two lists of lists, the sublists represent paths. I want to find all paths.
List<List<E>> pathList1
List<List<E>> pathList2
The naive solution of course:
List<List<E>> result = new ArrayList<List<E>>();
for(List<E> p1 : pathList1) {
for(List<E> p2: pathList2) {
List<E> newList = new ArrayList<E>(p1.size()+p2.size());
newList.addAll(p1);
newList.addAll(p2);
result.add(newList);
}
}
Unrelated theoretical question
I've recently learned about time complexity. So this is a self check, I hope someone can comment if I am correct.
Let N = num lists in pathList1
Let M = num lists in pathList2
Let X = average length of path in pathList1
Let Y = average length of path in pathList2
So if asked "What is the complexity of this function?" I would give
~O(NM(X + Y))
I was wondering if there was a faster way to do this?
Maybe a better data structure?
Do it concurrently?
Make some sort of "future" of sorts and return that instead? (Full disclosure, I'm 97% ignorant on futures).
I'm open to clever tricks and unique solutions, or purely practical.
Thanks.