Algorithmsinclusion exclusion application

Inclusion–Exclusion in Counting

TT
Testlaa Team
May 14, 20261 min read

Add sizes of single sets, subtract pairwise intersections, add triples—sign alternates.

Try this in Python

def ie3(a, b, c, ab, ac, bc, abc):
    return a + b + c - ab - ac - bc + abc

print(ie3(10, 10, 10, 3, 3, 3, 1))

Key takeaways

  • Ground sets must live in same universe.
  • In code, bitmask positions often replace explicit sets.
  • Stop at first nonzero layer if problem structure allows.

Tags:

CombinatoricsPythonStudents