Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Practice Mathematical Algorithm
  • Mathematical Algorithms
  • Pythagorean Triplet
  • Fibonacci Number
  • Euclidean Algorithm
  • LCM of Array
  • GCD of Array
  • Binomial Coefficient
  • Catalan Numbers
  • Sieve of Eratosthenes
  • Euler Totient Function
  • Modular Exponentiation
  • Modular Multiplicative Inverse
  • Stein's Algorithm
  • Juggler Sequence
  • Chinese Remainder Theorem
  • Quiz on Fibonacci Numbers
Open In App
Next Article:
Pigeonhole Principle for CP | Identification, Approach & Problems
Next article icon

Must do Math for Competitive Programming

Last Updated : 13 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Competitive Programming (CP) doesn’t typically require one to know high-level calculus or some rocket science. But there are some concepts and tricks which are sufficient most of the time. You can definitely start competitive coding without any mathematical background, but maths becomes essential as you dive deep into the world of CP.

A majority of the Competitive Coding problems that you'll encounter will have some mathematical logic or trick. All the algorithms that we learn are derived from a mathematical point of view. Most of the time, maths helps us solve the question within the necessary time constraints. 
All of the topics can’t be covered in a single article but we'll be looking into some of the most common mathematical concepts in competitive coding. Some of these concepts might look too difficult at first sight but applying them to problems will ease them for you. 

1. BigInteger 

For e. g. Calculating factorials of large numbers (lets say 100) or taking large numbers of input around 100000 digits in length. In c++, it is not possible to store these numbers even if we use long long int. One way to take this kind of number is, taking them into an array more wisely use a vector … each number will hold an index of the array, if the number is 12345 then 12345%10=5 will in index[4], and the number now=12345/10=1234. now 1234%10=4 will be in [3] and so on to 1%10=1 is in [0], or you can use string too, it is easier since the char array only allow 1 byte for each index so you don’t need that modulation operation to fit number into the index. 
Java provides Biginteger class to handle this.

2. GCD, LCM, Euclidean Algorithm, Extended Euclidean Algorithm 

  • LCM(a, b) * GCD(a, b) = a*b, calculating GCD is equivalent to calculating LCM. 

Now, how do we calculate the GCD of two numbers? 
We can of course find the factors of the two numbers and then determine the highest common factor. As the numbers get bigger though ( say 155566328819), factorization becomes ineffective. 
This is where Euclid's algorithm comes to our rescue. This algorithm uses the easy-to-prove fact gcd(a, b)=gcd(b, r), where r is the remainder when a is divided by b, or just a%b. 

C++
// Function to find the greatest common divisor (GCD) of two integers using Euclid's algorithm static int GCD(int A, int B) {     // Base case: if B is 0, return A as GCD     if (B == 0)         return A;     else         // Recursive case: call GCD recursively with B and the remainder of A divided by B         return GCD(B, A % B); } //this code is contributed by Utkarsh 
C
int GCD(int A, int B) {     if (B == 0)         return A;     else         return GCD(B, A % B); } 
Java
static int GCD(int A, int B) {     if (B == 0)         return A;     else         return GCD(B, A % B); }  // This code is contributed by susmitamittal1329. 
Python
def GCD(A, B):     if (B == 0):         return A     else:         return GCD(B, A % B)        # This code is contributed by subham348. 
C#
static int GCD(int A, int B) {     if (B == 0)         return A;     else         return GCD(B, A % B); }  // This code is contributed by subham348. 
JavaScript
function GCD(A, B) {     if (B === 0)         return A;     else         return GCD(B, A % B); }  // This code is contributed by subham348. 

Can we find the numbers (x, y) such that ux + vy = gcd(u, v)?. There exists infinitely many pairs - this is Bezout's Lemma. The algorithm to generate such pairs is called Extended Euclidean Algorithm.

3. Sieve of Eratosthenes and Segmented Sieve 

Generating primes fast is very important in some problems. Let's cut to the chase and introduce Eratosthenes's Sieve. You can use the Sieve of Eratosthenes to find all the prime numbers that are less than or equal to a given number N or to find out whether a number is a prime number. 
The basic idea behind the Sieve of Eratosthenes is that at each iteration one prime number is picked up and all its multiples are eliminated. After the elimination process is complete, all the unmarked numbers that remain are prime.

Suppose we want to find all primes between 2 and 50. Iterate from 2 to 50. We start with 2. Since it is not checked, it is a prime number. Now check all numbers that are multiple of except 2. Now we move on, to number 3. It's not checked, so it is a prime number. Now check all numbers that are multiple of 3, except 3. Now move on to 4. We see that this is checked - this is a multiple of 2! So 4 is not a prime. We continue doing this. 

C++
void sieve(int N) {     bool isPrime[N + 1];     for (int i = 0; i& lt; = N; ++i) {         isPrime[i] = true;     }      isPrime[0] = false;     isPrime[1] = false;      for (int i = 2; i * i <= N; ++i) {          // Mark all the multiples of i as composite numbers         if (isPrime[i] == true) {             for (int j = i * i; j <= N; j += i)                 isPrime[j] = false;         }     } } 
Java
// Java program for above approach import java.util.*;  class GFG {     public static void sieve(int N)     {         boolean isPrime[] = new boolean[N + 1];         for (int i = 0; i <= N; ++i) {             isPrime[i] = true;         }          isPrime[0] = false;         isPrime[1] = false;          for (int i = 2; i * i <= N; ++i) {              // Mark all the multiples of i as composite             // numbers             if (isPrime[i] == true) {                 for (int j = i * i; j <= N; j += i)                     isPrime[j] = false;             }         }     } } 
Python
def sieve(N):      isPrime = [True for i in range(N + 1)]      isPrime[0] = False     isPrime[1] = False      for i in range(2, int(N ** 0.5) + 1):          # Mark all the multiples of i as composite numbers         if (isPrime[i] == True):             for j in range(i * i, N + 1, i):                 isPrime[j] = False   # This code is contributed by phasing17. 
C#
// C# program for above approach  using System; using System.Collections.Generic;  class GFG {     public static void sieve(int N)     {         bool[] isPrime = new bool[N + 1];         for (int i = 0; i <= N; ++i) {             isPrime[i] = true;         }          isPrime[0] = false;         isPrime[1] = false;          for (int i = 2; i * i <= N; ++i) {              // Mark all the multiples of i as composite             // numbers             if (isPrime[i] == true) {                 for (int j = i * i; j <= N; j += i)                     isPrime[j] = false;             }         }     } }  // This code is contributed by phasing17 
JavaScript
function sieve( N) {     let isPrime = new Array(N + 1);     for (var i = 0; i <= N; ++i) {         isPrime[i] = true;     }      isPrime[0] = false;     isPrime[1] = false;      for (var i = 2; i * i <= N; ++i) {          // Mark all the multiples of i as composite numbers         if (isPrime[i] == true) {             for (var j = i * i; j <= N; j += i)                 isPrime[j] = false;         }     } }   // This code is contributed by phasing17 


What if the number is large (say 10^16), in that case we require segmented sieve.
The idea of segmented sieve is to divide the range [0..n-1] in different segments and compute primes in all segments one by one. This algorithm first uses Simple Sieve to find primes smaller than or equal to ?(n). Below are steps used in Segmented Sieve. 

  1. Use Simple Sieve to find all primes up to square root of ‘n’ and store these primes in an array “prime[]”. Store the found primes in an array ‘prime[]’. 
  2. We need all primes in range [0..n-1]. We divide this range in different segments such that size of every segment is at-most ?n 
  3. Do following for every segment [low....high] 
    • Create an array mark[high-low+1]. Here we need only O(x) space where x is number of elements in given range
    • Iterate through all primes found in step 1. For every prime, mark its multiples in given range [low..high]. 
      In Simple Sieve, we needed O(n) space which may not be feasible for large n. Here we need O(?n) space and we process smaller ranges at a time 

4. Modulo arithmetic, Modulo exponentiation and Modulo inverse 

When one number is divided by another, the modulo operation finds the remainder. It is denoted by the % symbol.
Example 
Assume that you have two numbers 10 and 3. 10%3 is 1 because when 10 is divided by 3, the remainder is 1.
Properties :
1. (a+b)%c = ((a%c)+(b%c))%c 
2. (a*b)%c = ((a%c)*(b%c))%c 
3. (a-b)%c = ((a%c)-(b%c)+c)%c 
4. (a/b)%c = ((a%c)?(b%c))%c 

When are these properties used? 
Assume that a = 10^12, b = 10^12, and c = 10^9+7. You have to find (a*b)%c. When you multiply a with b, the answer is 10^24, which does not confirm with the standard integer data types. Therefore, to avoid this we used the properties. (a*b)%c = ((a%c)*(b%c))%c
Fast Modulo exponentiation 
Calculate a^b in modular m in O(log b), 
It uses binary expansion of b, and is very straightforward. 

C++
ll expo(ll a, ll b, ll m) {     if (b == 0)         return 1;     ll p = expo(a, b / 2, m) % m;     p = (p * p) % m;      return (b % 2 == 0) ? p : (a * p) % m; } 
Java
// Java program to implement the approach  import java.util.*;  class GFG {     long expo(long a, long b, long m)     {         if (b == 0)             return 1;         long p = expo(a, b / 2, m) % m;         p = (p * p) % m;              return (b % 2 == 0) ? p : (a * p) % m;     }  }   // This code is contributed by phasing17 
Python
def expo(a, b, m):     if b == 0:         return 1     p = expo(a, b // 2, m) % m     p = (p * p) % m          return [p, (a * p) % m][b % 2] 
C#
// C# program to implement the approach  using System; using System.Collections.Generic;  class GFG {     long expo(long a, long b, long m)     {         if (b == 0)             return 1;         long p = expo(a, b / 2, m) % m;         p = (p * p) % m;              return (b % 2 == 0) ? p : (a * p) % m;     }  }   // This code is contributed by phasing17 
JavaScript
// JavaScript implementation of the approach  function expo(a, b, m) {     if (b == 0)         return 1;     let p = expo(a, Math.floor(b / 2), m) % m;     p = (p * p) % m;      return (b % 2 == 0) ? p : (a * p) % m; }   // This code is contributed by phasing17 


Now, let us talk about modular inverse.
By using Extended Euclidean Algorithm, we can get the inverse of a modulo m. 

C++
// Returns modulo inverse of a with respect  // to m using extended Euclid Algorithm  // Assumption: a and m are coprimes, i.e.,  // gcd(a, m) = 1  int modInverse(int a, int m)  {      int m0 = m;      int y = 0, x = 1;         if (m == 1)        return 0;         while (a > 1)      {          // q is quotient          int q = a / m;          int t = m;             // m is remainder now, process same as          // Euclid's algo          m = a % m, a = t;          t = y;             // Update y and x          y = x - q * y;          x = t;      }         // Make x positive      if (x < 0)         x += m0;         return x;  }  
Java
import java.util.*;  class GFG {      // Returns modulo inverse of a with respect     // to m using extended Euclid Algorithm     // Assumption: a and m are coprimes, i.e.,     // gcd(a, m) = 1     int modInverse(int a, int m)     {         int m0 = m;         int y = 0, x = 1;          if (m == 1)             return 0;          while (a > 1) {             // q is quotient             int q = a / m;             int t = m;              // m is remainder now, process same as             // Euclid's algo             m = a % m;             a = t;             t = y;              // Update y and x             y = x - q * y;             x = t;         }          // Make x positive         if (x < 0)             x += m0;          return x;     } } 
Python
# Python3 program to implement the approach  # This function returns modulo inverse of a with respect  # to m using extended Euclid Algorithm  # Assumption: a and m are coprimes, i.e.,  # gcd(a, m) = 1  def modInverse(a, m):       m0 = m;      y = 0     x = 1;         if (m == 1):       return 0;         while (a > 1) :               # q is quotient          q = int(a / m);          t = m;             # m is remainder now, process same as          # Euclid's algo          m = a % m         a = t;          t = y;             # Update y and x          y = x - q * y;          x = t;            # Make x positive      if (x < 0) :        x += m0;         return x;    # This code is contributed by phasing17 
C#
using System; using System.Collections.Generic;  class GFG {      // Returns modulo inverse of a with respect     // to m using extended Euclid Algorithm     // Assumption: a and m are coprimes, i.e.,     // gcd(a, m) = 1     int modInverse(int a, int m)     {         int m0 = m;         int y = 0, x = 1;          if (m == 1)             return 0;          while (a > 1) {             // q is quotient             int q = a / m;             int t = m;              // m is remainder now, process same as             // Euclid's algo             m = a % m;             a = t;             t = y;              // Update y and x             y = x - q * y;             x = t;         }          // Make x positive         if (x < 0)             x += m0;          return x;     } } 
JavaScript
// JS program to implement the approach   // This function returns modulo inverse of a with respect  // to m using extended Euclid Algorithm  // Assumption: a and m are coprimes, i.e.,  // gcd(a, m) = 1  function modInverse(a, m) {      let m0 = m;      let y = 0, x = 1;         if (m == 1)        return 0;         while (a > 1)      {          // q is quotient          let q = Math.floor(a / m);          let t = m;             // m is remainder now, process same as          // Euclid's algo          m = a % m, a = t;          t = y;             // Update y and x          y = x - q * y;          x = t;      }         // Make x positive      if (x < 0)         x += m0;         return x;  }    // This code is contributed by phasing17 


Fermat's Little Theorem gives a^(p-1)==a (mod p) if gcd(a, p)=1, where p is a prime. Therefore, we can calculate the modular inverse of a as a^(p-2), by fast exponentiation also.

5. Lucas Theorem

We can calculate nCr in modulo p (p is a prime) very fast using Lucas' Theorem. Lucas theorem basically suggests that the value of nCr can be computed by multiplying results of n(i)Cr(i) where n(i) and r(i) are individual same-positioned digits in base p representations of n and r respectively. This is very efficient when p is small and n, r is huge. We can precalculate the factorials and inverse of factorials modulo p by using the above code. 

6. Chinese Remainder Theorem< 

Two numbers (positive integers) a and b are relatively prime (prime to each other), if they have no common prime factors. The numbers m1, m2, ....mr, are pair wise relatively prime if any two distinct numbers in that collection, are relatively prime. Chinese remainder theorem says that given any r pair wise relatively prime numbers m1, m2, ....mr, and any numbers b1, b2, b3, ....br, we can always find a number M which leaves the remainders b1, b2, b3, ..br when it is divided by m1, m2, ...mr respectively. 
Let us solve x == r (mod mi), where mi are pairwise coprime. 
(If they are not coprime, break them into prime powers, and if some are contradictory, there are no solutions.)

7. Series and Sequences 

You just need to know some basics like : 

  • What is a series and does it converge to some value?
  • Know about famous series like trigonometric, hyperbolic…etc.
  • How to calculate the finite limit of famous series like ( geometric series, harmonic series) 

and basically the same thing for the sequences, you just need to know the basics. (Trick: use OEIS site) 
We sometimes land up in a situation when various coding problems can be simplified to a mathematical formula but often finding that formula isn’t that straightforward .Here comes, OEIS for rescue. We can calculate the terms for initial indices i.e n=0, 1, 2, 3, …….. and then may use OEIS to find the mathematical expression.

8. Catalan Numbers 

Catalan numbers are a sequence of natural numbers that helps to solve many counting problem. Terms starting with n=0 are : 1, 1, 2, 5, 14, 42, 132, 429, 1430 ….and so on. 
Questions based on catalan number may appear in many coding competitions. So it is always a plus point to know in depth about catalan number. 
Catalan numbers find extensive applications in forming closed solutions to combinatorics problems. Some of the examples are: 

  1. The number of binary search trees that can be formed using 'n' nodes is the nth Catalan number. 
  2. The number of ways that a convex polygon of n+2 sides, can be cut into 2 or more triangles by joining any 2 edges is the nth Catalan number. 
  3. The closed solution to the number of possible parentheses matching given 'n' pairs is the nth Catalan number.

9. Pigeonhole Principle 

The pigeonhole principle is a powerful tool used in combinatorial maths. But the idea is simple and can be explained by the following peculiar problem. Imagine that 3 pigeons need to be placed into 2 pigeonholes. Can it be done? The answer is yes, but there is one catch. The catch is that no matter how the pigeons are placed, one of the pigeonholes must contain more than one pigeon. 
The logic can be generalized for larger numbers.

The pigeonhole principle states that if more than n pigeons are placed into n pigeonholes, some pigeonhole must contain more than one pigeon. While the principle is evident, its implications are astounding.

For example consider this statement “If you pick five numbers from the integers 1 to 8, then two of them must add up to nine.” 
Explanation: Every number can be paired with another to sum to nine. In all, there are four such pairs: the numbers 1 and 8, 2 and 7, 3 and 6, and lastly 4 and 5.Each of the five numbers belongs to one of those four pairs. By the pigeonhole principle, two of the numbers must be from the same pair–which by construction sums to 9.

10. Inclusion Exclusion Principle 

Inclusion Exclusion principle is a very basic theorem of counting and many problems in various programming contests are based on it, a formal explanation of inclusion exclusion principle goes as follows: 
Consider A as a collection of objects and |A| as the number of objects in A and similarly for B, then the cardinality of collection of objects of both sets A and B ( when both A and B are disjoint) can be stated as (for 2 finite sets) : 

  • |AUB| = |A| + |B| 

But what if the sets are not disjoint? 
Then we need to subtract the common objects counted twice while calculating the cardinality of both A and B and new form will become: 

  • AUB| = |A| + |B| - |A ∩ B| 

This is the most basic form of the inclusion-exclusion principle. 
But what if there are more than 2 sets, let`s say n sets. 
Then it can be stated as : 

(Include=add, exclude=subtract) 
|A1 U A2 U A3 …..U AN| = (Include count of each set, Exclude count of pairwise set, Include count of triplet sets, exclude count of quadruplet sets……till nth tuple is included( if odd) or excluded( if even)) 
i. e., |A1 U A2 U A3 …..U AN| = (|A1| + |A2| + |A3| + |A4| … + |AN|) - ( |A1 ∩ A2| + |A1 ∩ A3| + |A1 ∩ A4|.. + all combinations) + (|A1 ∩ A2 ∩ A3| … all combinations)………. and so on.

This list is not exhaustive but the concepts will be very useful in contests in codeforces, codechef etc.. So grab your pen, paper and laptop and start practicing.
Happy coding!
 


Next Article
Pigeonhole Principle for CP | Identification, Approach & Problems

S

strangerr
Improve
Article Tags :
  • GBlog
  • Algorithms
  • Mathematical
  • Competitive Programming
  • Write From Home
  • DSA
  • GCD-LCM
  • catalan
  • Modular Arithmetic
  • GBlog-Competitive-Programming
Practice Tags :
  • Algorithms
  • Mathematical
  • Modular Arithmetic

Similar Reads

    Competitive Programming - A Complete Guide
    Competitive Programming is a mental sport that enables you to code a given problem under provided constraints. The purpose of this article is to guide every individual possessing a desire to excel in this sport. This article provides a detailed syllabus for Competitive Programming designed by indust
    8 min read
    Competitive Programming (CP) Handbook with Complete Roadmap
    Welcome to the Competitive Programming Handbook or CP Handbook by GeeksforGeeks! This Competitive Programming Handbook is a go-to resource for individuals aiming to enhance their problem-solving skills and excel in coding competitions. This CP handbook provides a comprehensive guide, covering fundam
    12 min read

    Mathematics for Competitive Programming

    Must do Math for Competitive Programming
    Competitive Programming (CP) doesn’t typically require one to know high-level calculus or some rocket science. But there are some concepts and tricks which are sufficient most of the time. You can definitely start competitive coding without any mathematical background, but maths becomes essential as
    15+ min read
    Pigeonhole Principle for CP | Identification, Approach & Problems
    In competitive programming, where people solve tough problems with computer code, the Pigeonhole Principle is like a secret tool. Even though it's a simple idea, it helps programmers tackle complex challenges. This article is your guide to understanding how this principle works and why it's crucial
    8 min read
    Euler Totient for Competitive Programming
    What is Euler Totient function(ETF)?Euler Totient Function or Phi-function for 'n', gives the count of integers in range '1' to 'n' that are co-prime to 'n'. It is denoted by \phi(n) .For example the below table shows the ETF value of first 15 positive integers: 3 Important Properties of Euler Totie
    8 min read
    Mathematics for Competitive Programming Course By GeeksforGeeks
    Mathematics forms the foundation of problem-solving in Competitive Programming (CP). Mastering key mathematical concepts is crucial for approaching algorithmic challenges effectively. If you're an aspiring competitive programmer or someone who wishes to enhance your problem-solving skills, this Math
    3 min read

    Number Theory for CP

    Binary Exponentiation for Competitive Programming
    In competitive programming, we often need to do a lot of big number calculations fast. Binary exponentiation is like a super shortcut for doing powers and can make programs faster. This article will show you how to use this powerful trick to enhance your coding skills. Table of ContentWhat is Binary
    15+ min read
    GCD (Greatest Common Divisor) Practice Problems for Competitive Programming
    GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers is the largest positive integer that divides both of the numbers.GCD of Two NumbersFastest Way to Compute GCDThe fastest way to find the Greatest Common Divisor (GCD) of two numbers is by using the Euclidean algorithm. The E
    4 min read

    Bit Manipulation for CP

    Bit Manipulation for Competitive Programming
    Bit manipulation is a technique in competitive programming that involves the manipulation of individual bits in binary representations of numbers. It is a valuable technique in competitive programming because it allows you to solve problems efficiently, often reducing time complexity and memory usag
    15+ min read
    Bit Tricks for Competitive Programming
    In competitive programming or in general, some problems seem difficult but can be solved very easily with little concepts of bit magic. We have discussed some tricks below in the previous post.Bitwise Hacks for Competitive Programming One-Liner Hacks of Bit Manipulation:One-Liner CodeFunctionx&1
    7 min read
    Bitwise Hacks for Competitive Programming
    Prerequisite: It is recommended to refer Interesting facts about Bitwise Operators How to set a bit in the number 'num': If we want to set a bit at nth position in the number 'num', it can be done using the 'OR' operator( | ).   First, we left shift '1' to n position via (1<<n)Then, use the 'O
    14 min read

    Combinatorics for CP

    Inclusion Exclusion principle for Competitive Programming
    What is the Inclusion-Exclusion Principle?The inclusion-exclusion principle is a combinatoric way of computing the size of multiple intersecting sets or the probability of complex overlapping events. Generalised Inclusion-Exclusion over Set:For 2 Intersecting Set A and B: A\bigcup B= A + B - A\bigca
    5 min read

    Greedy for CP

    Binary Search on Answer Tutorial with Problems
    Binary Search on Answer is the algorithm in which we are finding our answer with the help of some particular conditions. We have given a search space in which we take an element [mid] and check its validity as our answer, if it satisfies our given condition in the problem then we store its value and
    15+ min read
    Ternary Search for Competitive Programming
    Ternary search is a powerful algorithmic technique that plays a crucial role in competitive programming. This article explores the fundamentals of ternary search, idea behind ternary search with its use cases that will help solving complex optimization problems efficiently. Table of Content What is
    8 min read

    Array based concepts for CP

    What are Online and Offline query-based questions in Competitive Programming
    The query-based questions of competitive programming are mainly of two types: Offline Query.Online Query. Offline Query An offline algorithm allows us to manipulate the data to be queried before any answer is printed. This is usually only possible when the queries do not update the original element
    4 min read
    Precomputation Techniques for Competitive Programming
    What is the Pre-Computation Technique?Precomputation refers to the process of pre-calculating and storing the results of certain computations or data structures in advance, in order to speed up the execution time of a program. This can be useful in situations where the same calculations or data stru
    15+ min read
    PreComputation Technique on Arrays
    Precomputation refers to the process of pre-calculating and storing the results of certain computations or data structures(array in this case) in advance, in order to speed up the execution time of a program. This can be useful in situations where the same calculations are needed multiple times, as
    15 min read
    Frequency Measuring Techniques for Competitive Programming
    Measuring the frequency of elements in an array is a really handy skill and is required a lot of competitive coding problems. We, in a lot of problems, are required to measure the frequency of various elements like numbers, alphabets, symbols, etc. as a part of our problem. Examples: Input: arr[] =
    15+ min read

    Dynamic Programming (DP) for CP

    DP on Trees for Competitive Programming
    Dynamic Programming (DP) on trees is a powerful algorithmic technique commonly used in competitive programming. It involves solving various tree-related problems by efficiently calculating and storing intermediate results to optimize time complexity. By using the tree structure, DP on trees allows p
    15+ min read
    Dynamic Programming in Game Theory for Competitive Programming
    In the fast-paced world of competitive programming, mastering dynamic programming in game theory is the key to solving complex strategic challenges. This article explores how dynamic programming in game theory can enhance your problem-solving skills and strategic insights, giving you a competitive e
    15+ min read

    Game Theory for CP

    Interactive Problems in Competitive Programming
    Interactive Problems are those problems in which our solution or code interacts with the judge in real time. When we develop a solution for an Interactive Problem then the input data given to our solution may not be predetermined but is built for that problem specifically. The solution performs a se
    6 min read
    Mastering Bracket Problems for Competitive Programming
    Bracket problems in programming typically refer to problems that involve working with parentheses, and/or braces in expressions or sequences. It typically refers to problems related to the correct and balanced usage of parentheses, and braces in expressions or code. These problems often involve chec
    4 min read
    MEX (Minimum Excluded) in Competitive Programming
    MEX of a sequence or an array is the smallest non-negative integer that is not present in the sequence.Note: The MEX of an array of size N cannot be greater than N since the MEX of an array is the smallest non-negative integer not present in the array and array having size N can only cover integers
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences