venn algorithm