An initiative by enjoyalgorithms! We design content with in-depth explanations and help learners develop a dedicated interest in math, logic and algorithms.
Just like programming, math is one of the core parts of learning data structures and algorithms. We mainly use math to analyse efficiency of various algorithms. But sometimes, the problem itself contains mathematical property or requires some mathematical insight to find a solution.
Problem description of the tower of Hanoi: Given a stack of n disks arranged from largest on the bottom to smallest on top placed on a rod A, together with two empty rods B and C. The objective is to move the n disks from rod A to rod C using rod B.
The sieve of Eratosthenes is an ancient and efficient algorithm for finding all primes numbers from 2 to n. This algorithm finds all the prime numbers in a segment using O(nloglogn) operations.
Given a positive integer n, write a program to check if the number is prime or not. A number n > 1 is said to be a prime number if 1 and n are its only factors. In other words, a prime number is a number that is divisible only by two numbers itself and one.
The birthday paradox is strange and counter-intuitive. It's a "paradox" because our brain find it difficult to handle the compounding power of exponents. Real-world applications for this include a cryptographic attack called the "birthday attack".
There are 25 horses among which we need to find out the fastest 3 horses. In each race, only 5 horses can run simultaneously because there are only 5 tracks. What is the minimum number of races required to find the 3 fastest horses without using a stopwatch?