Given a list of elements, how to process all elements if every element requires knowledge about states of every other element of this list?
For example, direct way to implement it in Python could be:
S = [1,2,3,4]
for e in S:
for j in S:
if e!=j:
process_it(e,j)
but it is very slow O(n²) if number of elements is huge. There must be another effective way, involving concurrency as well. Can you help me?