Skip to main content

Basics of Combinatorics



Counting the objects that satisfy some criteria is a very common task in both Programming and in real-life situations. The myriad ways of counting the number of elements in a set is one of the main tasks in combinatorics, and I’ll try to describe some basic aspects of it in this blog.

Combinatorics is all about number of ways of choosing some objects out of a collection and/or number of ways of their arrangement. For example suppose there are five members in a club, let's say there names are A, B, C, D, and E, and one of them is to be chosen as the coordinator. Clearly any one out of them can be chosen so there are 5 ways. Now suppose two members are to be chosen for the position of coordinator and co-coordinator. Now, we can choose A as coordinator and one out of the rest 4 as co-coordinator. Similarly we can choose B as coordinator and one of out the remaining 4 as co-coordinator, and similarly with C, D and E. So there will be total 20 possible ways.

Combinatorial primitives

Let’s begin with a quick overview of the basic rules and objects that we will reference later.

The rule of sum


The rule of product


Let's generalize it. Permutations of choosing R disticnt objects out of a collection of N objects can be calculated using the following formula:


Combinations of choosing R distinct objects out of a collection of N objects can be calculated using the following formula:

Basic Combinatorics Rules:

Suppose there are two sets A and B.
The basic rules of combinatorics one must remember are:
  1. The Rule of Product:
    The product rule states that if there are X number of ways to choose one element from A and Y number of ways to choose one element from B, then there will be X*Y number of ways to choose two elements, one from A and one from B.
  2. The Rule of Sum:
    The sum rule states that if there are X number of ways to choose one element from A and Y number of ways to choose one element from B, then there will be X+Y number of ways to choose one element that can belong to either A or to B.

These rules can be used for a finite collections of sets.

Permutations with repetition:

If we have N objects out of which N1 objects are of type 1,N2 objects are of type 2, ... Nk objects are of type k, then number of ways of arrangement of these N objects are given by:

Permutations without repetition:

When we choose k objects from n-element set in such a way that the order matters and each object can be chosen only once:

Combinations with repetition:

If we have N elements out of which we want to choose K elements and it is allowed to choose one element more than once, then number of ways are given by:

Combinations without repetition:

In combinations we choose a set of elements (rather than an arrangement, as in permutations) so the order doesn’t matter. The number of different k-element subsets (when each element can be chosen only once) of n-element set is:
In this blog we discussed about combinatorics, it focused mainly on the basic aspects and methods of counting. To learn more, I recommend you check out the reference works listed below, and keep practicing !!

References:

Comments

Popular posts from this blog

Finding all Primes Up-to N using Sieve of Eratosthenes

                                                                                                   -By: Sambhav Sieve of Eratosthenes For Finding all Primes Up-to N. Hello Friends, Welcome to my first blog on competitive programming. Today, I am going to illuminate one fascinating mathematical concept that can give you an edge over others in coding contest. As you might have already figured out that today’s topic of discussion is about Sieve of primes using the Eratosthenes’s approach. So, without wasting much time, let’s get started. /* Before I tell you the Statement of the problem. Let us see what are prime numbers and how we can figure out whether a number is prime or not. */ A prime number is a whole number greater th...

Mathematics For Competitive Programming

  I have seen a number of competitors complain that they are unfairly disadvantaged because many competitive programming platform problems are too mathematical. Personally, I love mathematics and thus I am biased in this issue. Nevertheless, I strongly believe that problems should contain at least some math, because mathematics and computer science often go hand in hand. It is hard to imagine a world where these two fields could exist without any interaction with each other. These days, a great deal of applied mathematics is performed on computers such as solving large systems of equations and approximating solutions to differential equations for which no closed formula exists. Mathematics is widely used in computer science research, as well as being heavily applied to graph algorithms and areas of computer vision. In this blog we will see theory and practical application to some of the more common mathematical constructs. The topics covered are: primes, GCD, Quadratic Equations, P...