I\'ll try to explain the problem in the math language.
Assume I have a set of items X = {x_1, x_2, ..., x_n}
. Each item of X
belongs to one of
I don't got the answer because you asked very abstract question but I will give you an idea.
Try think multiThreading. For instance you can create a thread pool with a limited number of threads. Then find a recursion solution and start new task for each loop when you are diving inside.
I am saying as you be able to split this problem to many small task as better your algorithm will be.
Think problematically not mathematically!