Orbit counting theorem or Burnside's Lemma - GeeksforGeeks

03 Mar, 2022
Burnside’s Lemma is also sometimes known as orbit counting theorem. It is one of the results of group theory. It is used to count distinct objects with respect to symmetry. It basically gives us the formula to count the total number of combinations, where two objects that are symmetrical to each other with respect to rotation or reflection are counted as a single representative.
Therefore, Burnside Lemma’s states that total number of distinct object is: where:  
c(k) is the number of combination that remains unchanged when Kth rotation is applied, and
N is the total number of ways to change the position of N elements.
For Example:Let us consider we have a necklace of N stones and we can color it with M colors. If two necklaces are similar after rotation then the two necklaces are considered to be similar and counted as one different combination. Now Let’s suppose we have N = 4 stones with M = 3 colors, then
Since we have N stones, therefore, we have N possible variations of each necklace by rotation: 
Observations: There are N ways to change the position of the necklace as we can rotate it by 0 to N – 1 time.
There are ways to color a necklace. If the number of rotations is 0, then all ways remain different.If the number of rotation is 1, then there are only M necklaces which will be different out of all ways.Generally, if the number of rotations is K, necklaces will remain the same out of all ways.
There are ways to color a necklace. If the number of rotations is 0, then all ways remain different.
If the number of rotation is 1, then there are only M necklaces which will be different out of all ways.
Generally, if the number of rotations is K, necklaces will remain the same out of all ways.
Therefore, for a total number of distinct necklaces of N stones after coloring with M colors is the summation of all the distinct necklaces at each rotation. It is given by: 
Below is the implementation of the above approach: 
C++
Java
C#
Javascript
// C++ program for implementing the// Orbit counting theorem// or Burnside's Lemma #include <bits/stdc++.h>using namespace std; // Function to find result using// Orbit counting theorem// or Burnside's Lemmavoid countDistinctWays(int N, int M){     int ans = 0;     // According to Burnside's Lemma    // calculate distinct ways for each    // rotation    for (int i = 0; i < N; i++) {         // Find GCD        int K = __gcd(i, N);        ans += pow(M, K);    }     // Divide By N    ans /= N;     // Print the distinct ways    cout << ans << endl;} // Driver Codeint main(){     // N stones and M colors    int N = 4, M = 3;     // Function call    countDistinctWays(N, M);     return 0;}
// Java program for implementing the// Orbit counting theorem// or Burnside's Lemmaclass GFG{ static int gcd(int a, int b){    if (a == 0)        return b;             return gcd(b % a, a);} // Function to find result using// Orbit counting theorem// or Burnside's Lemmastatic void countDistinctWays(int N, int M){    int ans = 0;     // According to Burnside's Lemma    // calculate distinct ways for each    // rotation    for(int i = 0; i < N; i++)    {        // Find GCD        int K = gcd(i, N);        ans += Math.pow(M, K);    }     // Divide By N    ans /= N;     // Print the distinct ways    System.out.print(ans);} // Driver Codepublic static void main(String []args){         // N stones and M colors    int N = 4, M = 3;     // Function call    countDistinctWays(N, M);}} // This code is contributed by rutvik_56
// C# program for implementing the// Orbit counting theorem// or Burnside's Lemmausing System;class GFG{static int gcd(int a, int b){    if (a == 0)        return b;           return gcd(b % a, a);} // Function to find result using// Orbit counting theorem// or Burnside's Lemmastatic void countDistinctWays(int N, int M){    int ans = 0;     // According to Burnside's Lemma    // calculate distinct ways for each    // rotation    for(int i = 0; i < N; i++)    {        // Find GCD        int K = gcd(i, N);        ans += (int)Math.Pow(M, K);    }     // Divide By N    ans /= N;     // Print the distinct ways    Console.Write(ans);} // Driver Codepublic static void Main(string []args){         // N stones and M colors    int N = 4, M = 3;     // Function call    countDistinctWays(N, M);}} // This code is contributed by pratham76
<script> // Javascript <script> // Javascript program for implementing the// Orbit counting theorem// or Burnside's Lemma function gcd(a, b){    if (a == 0)        return b;              return gcd(b % a, a);}  // Function to find result using// Orbit counting theorem// or Burnside's Lemmafunction countDistinctWays(N, M){    let ans = 0;      // According to Burnside's Lemma    // calculate distinct ways for each    // rotation    for(let i = 0; i < N; i++)    {        // Find GCD        let K = gcd(i, N);        ans += Math.pow(M, K);    }      // Divide By N    ans /= N;      // Print the distinct ways    document.write(ans);} // Driver Code         // N stones and M colors    let N = 4, M = 3;      // Function call    countDistinctWays(N, M);       </script>
24
 
rutvik_56
pratham76
susmitakundugoaldanga
sweetyty
Combinatorial
Mathematical
Mathematical
Combinatorial
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Ways to sum to N using Natural Numbers up to K with repetitions allowed
Generate all possible combinations of K numbers that sums to N
Combinations with repetitions
Largest substring with same Characters
Generate all possible combinations of at most X characters from a given array
Program for Fibonacci numbers
Set in C++ Standard Template Library (STL)
C++ Data Types
Coin Change | DP-7
Merge two sorted arrays