# Given collection of sets how to turn it to collection of disjoint sets?

Suppose we have a finite collection of sets $A_1$,...,$A_n$. Is there an algorithm which gives a new collection $B_1$,...,$B_m$, which consist of pairwise disjoint sets, $\cup B_i=\cup A_j$ and each $B_i$ is a subset of some $A_j$?

-

Write $B_k=A_k\setminus\bigcup_{j<k}A_j$. It might be the case that several of the sets will end up as being empty. Remove those.