
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Explore how algorithms in competitive programming blend mathematics with proofs and efficiency. Move from problem description to brute-force ideas, correctness proofs, and time and space concepts, covering modular arithmetic.
Explore time and space complexity, compare algorithm performance, and apply order of growth and Big O notation to choose efficient solutions using simple vector examples.
In this short lecture, we will be working through 2 examples on how to compute time&space complexity.
Explore binary exponentiation by expressing the exponent in binary, multiplying the base when a bit is one, squaring the base, and shifting through digits to run in log n time.
Learn prime factorization via the fundamental theorem of arithmetic, illustrated by 500 = 2^2 times 5^3, using a square-root factoring method with division until no factor remains, yielding O(sqrt(n)) time.
Apply the inclusion-exclusion principle to compute the union size of multiple sets by adding sizes, subtracting pairwise intersections, and adding back triple intersections.
Frame the inclusion-exclusion principle as a binary-subset algorithm to compute the union size of events, using lcm intersections of primes and alternating sums to achieve an O(2^N) complexity.
Discover how the Euclidean algorithm quickly finds the greatest common divisor of two integers by iterating with remainders until one number becomes zero, with concise code and time efficiency.
Demonstrate the correctness of the Euclidean algorithm by proving gcd(a,b) = gcd(b, a − b) and show that each iteration reduces the two numbers, eventually terminating.
Explore the extended euclidean algorithm to solve a x + b y = c, requiring c is a multiple of gcd(a,b), and use backward substitution to obtain x and y.
Demonstrates the extended euclidean algorithm by iterating to obtain gcd and coefficients x and y, with a c++ four-parameter implementation and base case x=1, y=0, time complexity O(log n).
Explore the sieve of Eratosthenes to find primes by marking multiples as composite, illustrated from 1 to 20; identify the naive approach and its inefficiency.
Explore the proof of time complexity for a method that marks composites using the smallest prime factor, showing each number is visited once and prime factors determine the products.
Explore Euler's totient function and its phi formula, compute phi(n) using prime factors, and understand how multiples and prime factors shape the calculation.
Learn how to solve linear systems with Gaussian elimination, using row operations and pivoting to reach an identity form, and understand degenerate cases and algorithm complexity.
Demonstrates gaussian elimination code: select pivot by max absolute value, handle zeros with epsilon, swap and reduce rows, then back-substitute to classify no, unique, or infinite solutions.
Discover how modular inverses enable division in competitive programming, and how the extended Euclidean algorithm computes the inverse when gcd(a, m) = 1.
Demonstrate a code implementation of the extended Euclidean algorithm to compute the multiplicative inverse modulo B, returning X as the inverse and swapping X and Y for the general case.
explore the chinese remainder theorem idea for solving systems of congruences with coprime moduli by constructing X from a_i, M_i, and modular inverses, and analyze its proof and complexity.
Implement a chinese remainder theorem solver in code by computing the product M, modular inverses via the extended Euclidean algorithm, and summing ai * mi * inverse modulo M.
Conclude this course by recapping the basic techniques, the extended Euclidean theorem and algorithm, the sieve of Eratosthenes, and modular arithmetic. Anticipate tougher math puzzles in future topics.
This is a series of courses on popular algorithms used especially in the field of competitive programming!
Competitive programming is a mental sport that tests students on a variety of logical or mathematical problems, and the use of algorithms is essential in improving the efficiency of your solution.
The aim of competitive programming is to write source code of computer programs that are able to solve given problems. Typical such tasks belong to one of the following categories: combinatorics, number theory, graph theory, algorithmic game theory, computational geometry, string analysis, and data structures.
This course focuses not only on the implementation of algorithms but also on the mathematics behind these algorithms since they are requisite in understanding the correctness and efficiency of the algorithms. Specifically, rigid proofs for algorithms will be covered in this series of lectures.
Here, we will be starting with maths puzzles, where the link to mathematics is the most apparent! Hope you will be learning something useful in this course!
If you find this course intriguing or you want to learn more about competitive programming algorithms, please look forward to future addition to the series!
A typical course structure is as follows:
- Problem description
- A naive approach
- Introducing the algorithm
- Mathematical proof of the correctness and efficiency of the algorithm
- A sample problem
- Short quiz
- Hands-on practice