Found 7197 Articles for C++

C++ Program to Compute Discrete Fourier Transform Using Naive Approach

Ravi Ranjan
Updated on 26-May-2025 11:52:03

3K+ Views

DFT stands for Discrete Fourier Transform. DFT is a mathematical technique in which we convert the signals of the time domain to their respective signal in the frequency domain, i.e., converting into a list of numbers that tell us which frequencies are present in that signal. Here, by time signal, we mean signals such as audio, temperature, etc that changes over time. The frequency signal means the frequency of each signal present in the time signal. The numbers that tell us which frequencies are present in the signal are called the coefficients. In this article, our task is to compute ... Read More

C++ Program to Compute DFT Coefficients Directly

Ravi Ranjan
Updated on 26-May-2025 11:51:43

324 Views

DFT stands for Discrete Fourier Transform. DFT is a mathematical technique in which we convert the signals of the time domain to their respective signal in the frequency domain, i.e., converting into a list of numbers that tell us which frequencies are present in that signal. Here, by time signal, we mean signals such as audio, temperature, etc. that changes over time. The frequency signal means the frequency of each signal present in the time signal. The numbers that tell us which frequencies are present in the signal are called the coefficients. In this article, our task is to compute ... Read More

C++ Program to Implement the Bin Packing Algorithm

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

1K+ Views

The bin packing problem is a special type of cutting stock problem. In the bin packing problem, objects of different volumes must be packed into a finite number of containers or bins each of volume V in a way that minimizes the number of bins used. In computational complexity theory, it is a combinational NP-hard problem.When the number of bins is restricted to 1 and each item is characterized by both a volume and a value, the problem of maximizing the value of items that can fit in the bin is known as the knapsack problem.AlgorithmBegin    Binpacking(pointer, size, no ... Read More

C++ Program to Perform Partition of an Integer in All Possible Ways

Daniol Thomas
Updated on 28-Apr-2025 16:04:22

953 Views

In this article, we have a positive integer 'n'. Our task is to generate all possible unique ways to represent 'n' as the sum of positive integers in C++. Each partition should give a sum equal to the given 'n'. Here is an example: Input: n = 4 Output: 4 3 1 2 2 2 1 1 1 1 1 1 Steps to Perform Unique Partition of Integer We start with the current partition i.e. with an initial value of n. Then we print the current partition. ... Read More

C++ Program to Solve the Fractional Knapsack Problem

Daniol Thomas
Updated on 17-Feb-2022 13:07:35

7K+ Views

In Fractional knapsack problem, a set of items are given, each with a weight and a value. We need to break items for maximizing the total value of knapsack and this can be done in greedy approach.AlgorithmBegin Take an array of structure Item Declare value, weight, knapsack weight and density Calculate density=value/weight for each item Sorting the items array on the order of decreasing density We add values from the top of the array to total value until the bag is full, i.e; total value

C++ Program to Solve the 0-1 Knapsack Problem

Nancy Den
Updated on 29-Apr-2025 15:35:40

6K+ Views

In the 0-1 knapsack problem, a set of items is given, each with a weight and a value. We need to determine the number of each item to include in a collection so that the total weight is less than or equal to the given limit and the total value is as large as possible.ExampleThe following example explains the 0-1 knapsack problem: Input: Weights: 1 2 3 6 7 4 Values: 10 20 25 40 60 70 Max Weight Capacity: 7 Output: Maximum value: 100 Here is an explanation of the above example: Weights: ... Read More

C++ Program to Implement Fermat’s Little Theorem

Ravi Ranjan
Updated on 23-Apr-2025 17:07:46

949 Views

Fermat's Little Theorem states that if p is a prime number and a is an integer not divisible by p, then a^(p-1) is congruent to 1 modulo p. It can be represented as a(p-1) ≡ 1 (mod p). It can also be said that if any integer a is raised to the (p-1) where p is a prime and gcd(a, p) =1, then a^(p-1)-1 is divisible by p. In this article, we have two integers i.e. 'a' and a prime number 'p' such that a is not divisible by p. Our task is to implement Fermat's Little theorem using these ... Read More

C++ Program to Implement Extended Euclidean Algorithm

Ravi Ranjan
Updated on 07-May-2025 14:10:09

2K+ Views

The extended euclidean algorithms find the greatest common divisor (GCD) of two numbers in the form of ax + by = gcd(a, b). This expression is also known as Bezout's Identity. The extended Euclidean algorithm is an extension of the Euclid algorithm that is also used to find the GCD of two numbers using repetitive division. In this article, we have two numbers and our task is to implement the extended Euclidean algorithm to find the GCD of these two numbers in C++. Steps To Implement Extended Euclidean Algorithm The steps to implement an extended Euclidean algorithm are as ... Read More

C++ Program to Implement Euler Theorem

Ravi Ranjan
Updated on 23-Apr-2025 17:13:22

639 Views

Euler's theorem states that if two numbers (a and n), are co-prime i.e. gcd(a, n)=1, then 'a' raised to the power of Euler's totient function of n (a^φ(n)) is congruent to 1 modulo n i.e. a^φ(n) ≡ 1 (mod n). The Euler's Totient Function is denoted as φ(n) and represents the count of integers from 1 to n that are relatively co-prime to n. In this article, we have two co-prime integers. Our task is to implement the Euler Theorem in C++ using given co-prime numbers. Here is an example to verify the Euler Theorem for two co-prime numbers: ... Read More

C++ Program to Implement Russian Peasant Multiplication

Ravi Ranjan
Updated on 22-Apr-2025 16:50:55

561 Views

The Russian Peasant multiplication is used to multiply two numbers without using the multiplication operator. It involves constant use of halving and doubling the numbers. In this article, we have two integers, our task is to find the product of these two integers by implementing russian peasant multiplication in C++. Steps to Implement Russian Peasant Multiplication We will follow these simple steps to find the product using Russian Peasant multiplication: We have created a function russianPeasant() that accepts both the numbers (n and m) as arguments. Then we used a ... Read More

Advertisements