Found 7346 Articles for C++

C++ Program to Find Maximum Value of any Algebraic Expression

Smita Kapse
Updated on 30-Jul-2019 22:30:25

213 Views

This is a C++ Program to Find Maximum Value of any Algebraic Expression.An algebraic expression of the form (x1 + x2 + x3 + . . . + xa) * (y1 + y2 + . . . + yb) and (a + b) integers is given.consider all possible combinations of a numbers and remaining b numbers and calculating their values, from which maximum value can be derived.AlgorithmBegin    function MaxValue() :    Arguments:    a[]=array which store the elements.    x, y=integers.    Body of the function:    1) Find the sum of array elements.    2) Initialize s = ... Read More

C++ Program to Find Minimum Value of any Algebraic Expression

Anvi Jain
Updated on 30-Jul-2019 22:30:25

213 Views

This is a C++ Program to Find Minimum Value of any Algebraic Expression.An algebraic expression of the form (x1 + x2 + x3 + . . . + xa) * (y1 + y2 + . . . + yb) and (a + b) integers is given.consider all possible combinations of a numbers and remaining b numbers and calculating their values, from which minimum value can be derived.AlgorithmBegin    function MaxValue() :    Arguments:    a[] = array which store the elements.    x, y = integers.    Body of the function:    1) Find the sum of array elements.   ... Read More

C++ Program to Find Basis and Dimension of a Matrix

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

162 Views

This is a C++ program to find Basis and Dimension of a Matrix.AlgorithmBegin    Function determinant() :    It calculates determinant of the matrix.    /*       Arguments:       n = number of elements.       matrix[10][10] = input matrix.    */    declare the submatrix submatrix[10][10].    //Body of the function:    if (n == 2)       return ((matrix[0][0] * matrix[1][1]) - (matrix[1][0] * matrix[0][1]))    else       Make a for loop c = 0 to n-1          Declare and initialize submati = 0, submatj.     ... Read More

C++ Program to Perform Optimal Paranthesization Using Dynamic Programming

Smita Kapse
Updated on 30-Jul-2019 22:30:25

141 Views

This is a C++ program to perform Optimal Paranthesization using Dynamic Programming.AlgorithmBegin    Take the length n and dimension of matrix as input.    MatrixChain() to find out minimum multiplications:    Arguments:       a[i][j]=Minimum number of scalar multiplications needed to          compute the matrix A[i]A[i+1]...A[j] = A[i..j] where dimension of A[i] is p[i-1] x p[i].          a[i][j] means cost is zero when multiplying one matrix.       L is chain length.       m = cost / scalar multiplications.    Body of the function:       for i = ... Read More

C++ Program to Optimize Wire Length in Electrical Circuit

Anvi Jain
Updated on 30-Jul-2019 22:30:25

249 Views

This is a C++ Program to optimize Wire Length in Electrical Circuit.AlgorithmBegin    Function optimizeLength() :    1) Declare a array dist[N].    2) sptSet[i] will be true if component i is included in shortest    path tree or shortest distance from src to i is finalized.    3) Initialize all distances as INFINITE and stpSet[] as false    4) Distance of source component from itself will be always 0.    5) Run a for loop cnt = 0 to N-2, Find shortest path for all components.       A) Pick the minimum distance component from the set of ... Read More

C++ Program to Represent Linear Equations in Matrix Form

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

416 Views

This is a C++ program to represent Linear Equations in matrix form.AlgorithmBegin    1) Take the no of variables n and the coefficients of each variable as input.    2) Declare a matrix[n][n] and constant[n][1].    3) Make for loops i = 0 to n-1 and j = 0 to n-1    to take the coefficients of each variable as the elements of the matrix.    4) Display the matrix by using nested for loops. EndExample#include using namespace std; int main(void) {    char variable[] = { 'x', 'y', 'z', 'd' };    cout > n;    cout > matrix[i][j];       }       cin >> constant[i][0];    }    cout

C++ Program to Implement Gauss Seidel Method

Smita Kapse
Updated on 30-Jul-2019 22:30:25

3K+ Views

Gauss Seidel method is used to solve linear system of equations in iterative method. This is a C++ Program to Implement Gauss Seidel Method.AlgorithmBegin    Take the dimensions of the matrix p and its elements as input.    Take the initials values of x and no of iteration q as input.    While q>0       Make a for loop i = 0 to p-1          initialize n[i] = (b[i] / a[i][i]).             Make a for loop i = 0 to p-1             If (j == ... Read More

C++ Program to Implement Gauss Jordan Elimination

Anvi Jain
Updated on 30-Jul-2019 22:30:25

5K+ Views

This is a C++ Program to Implement Gauss Jordan Elimination. It is used to analyze linear system of simultaneous equations. It is mainly focused on reducing the system of equations to a diagonal matrix form by row operations such that the solution is obtained directly.AlgorithmBegin    n = size of the input matrix    To find the elements of the diagonal matrix:    Make nested for loops j = 0 to n and i = 0 to n       The element in the first row and the first column is made 1       and then the ... Read More

C++ Program to Implement Coppersmith Freivald’s Algorithm

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

384 Views

Freivalds' algorithm determines whether the matrices are equal for a chosen k value with a probability of failure less than 2^-k in O(kn^2).It is used to verify matrix multiplication.AlgorithmBegin    Take matrix1(n*n), matrix2(n*n), matrix3(n*n) as input.    // According to the algorithm we have to verify:    // matrix1 × matrix2 = matrix3.    1) Choose vector a[n][1] randomly and uniformly in which component will be 0 or 1.    2) Compute matrix2 * a, matrix3 * a and then matrix1 * (matrix2 * a) for evaluating the expression, matrix1 * (matrix2 * a) - matrix3 * a.    3) ... Read More

C++ Program to Implement Disjoint Set Data Structure

Smita Kapse
Updated on 30-Jul-2019 22:30:25

3K+ Views

Disjoint set is basically as group of sets where no item can be in more than one set. It supports union and find operation on subsets.Find(): It is used to find in which subset a particular element is in and returns the representative of that particular set.Union(): It merges two different subsets into a single subset and representative of one set becomes representative of other.Functions and pseudocodesBegin    Assume k is the element    makeset(k):       k.parent = k.    Find(x):    If k.parent == k       return k.    else    return Find(k.parent)    Union ... Read More

Advertisements