Found 33676 Articles for Programming

C++ Program to Find Hamiltonian Cycle in an UnWeighted Graph

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

2K+ Views

A Hamiltonian cycle is a Hamiltonian Path such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path. It is in an undirected graph is a path that visits each vertex of the graph exactly once.Functions and purposesBegin    1. function isSafe() is used to check for whether it is    adjacent to the previously added vertex and already not added.    2. function hamiltonianCycle() solves the hamiltonian problem.    3. function hamCycle() uses hamiltonianCycle() to solve    the hamiltonian problem. It returns false if there is no    Hamiltonian Cycle ... Read More

C++ Program to Find a Good Feedback Edge Set in a Graph

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

211 Views

In this Program we will basically find a feedback arc set which contains edges which when removed from the graph, graph becomes directed acyclic graph.AlgorithmBegin function checkCG(int n) : n: number of vertices. arr: struct graph variable. Initialize cnt = 0 and size = (n-1). For i =0 to n-1    if (cnt == size)       return 0    if (arr[i].ptr == NULL)       Increase cnt.       for j = 0 to n-1          while (arr[j].ptr != NULL)             if ((arr[j].ptr)->des == (arr[i].ptr)->des)       ... Read More

C++ Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected

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

404 Views

In this program we need to find the Edge Connectivity of a Graph. An Edge Connectivity of a Graph of a graph means it is a bridge, removing it graph will be disconnected. Number of connected components increases with the removing of bridge in a disconnected undirected graph.Functions and pseudocodeBegin    Function connections() is a recursive function to find out the connections:    A) Mark the current node un visited.    B) Initialize time and low value    C) Go through all vertices adjacent to this    D) Check if the subtree rooted with x has a connection to one ... Read More

C++ Program to Check if a Given Graph must Contain Hamiltonian Cycle or Not

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

225 Views

A Hamiltonian cycle is a Hamiltonian Path such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path. It is in an undirected graph is a path that visits each vertex of the graph exactly once.Functions and purposesBegin    1. function isSafe() is used to check for whether it is    adjacent to the previously added vertex and already not added.    2. function hamiltonianCycle() solves the hamiltonian problem.    3. function hamCycle() uses hamiltonianCycle() to solve the hamiltonian problem. It returns false if there is no    Hamiltonian Cycle possible, ... Read More

C++ Program to Construct a Random Graph by the Method of Random Edge Selection

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

170 Views

In this program a random graph is generated for random vertices and edges. The time complexity of this program is O(v*e). Where v is the number of vertices and e is the number of edges.AlgorithmBegin    Develop a function GenRandomGraphs(), with ‘e’ as the    number of edges and ‘v’ as the number of vertexes, in the argument list.    Assign random values to the number of vertex and edges of the graph, Using rand() function.       Print the connections of each vertex, irrespective of the direction.       Print “Isolated vertex” for the vertex having no ... Read More

C++ Program to Generate N Number of Passwords of Length M Each

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

270 Views

This is a C++ Program to Generate N Number of Passwords of Length M Each.AlgorithmBegin    Take the length of password as input.    function permutation() generate random passwords:    /* Arguments       A pointer array a.       Total Number of random numbers m.       Length of the password s.    */    // Body of the function:    if (m == s)       for i = 0 to s-1          Print *(a + i)    else       for i = m to s-1       ... Read More

C++ Program to Implement Modular Exponentiation Algorithm

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

2K+ Views

This is a C++ program to implement Modular Exponentiation Algorithm.AlgorithmBegin    function modular():    // Arguments: base, exp, mod.    // Body of the function:       initialize res = 1       while (exp > 0)          if (exp mod 2 == 1)          res= (res * base) % mod          exp = exp left shift 1          base = (base * base) % mod       return res. EndExample#include using namespace std; long long modular(long long base, long long exp, int mod) {    long long res = 1;    while (exp > 0) {       if (exp % 2 == 1)          res= (res * base) % mod;       exp = exp >> 1;       base = (base * base) % mod;    }    return res; } int main() {    long long b, e;    int mod;    coutb;    coute;    coutmod;    cout

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

Nishu Kumari
Updated on 29-May-2025 19:24:10

297 Views

The algebraic expression is a combination of numbers, variables (x or y), and arithmetic operators like +, -, *, and /. In this article, we'll write a C++ program to find the maximum value of an expression in the form (x1 + x2 + x3 + . . . + xa) * (y1 + y2 + . . . + yb) where a total of a+b integers are given. Our task is to split these integers into two groups, one with a numbers and the other with b numbers, and calculate the product of their sums. By ... Read More

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

Nishu Kumari
Updated on 29-May-2025 19:24:33

299 Views

The algebraic expression is a combination of numbers, variables (x or y), and arithmetic operators like +, -, *, and /. In this article, we'll write a C++ program to find the minimum value of an expression in the form (x1 + x2 + x3 + . . . + xa) * (y1 + y2 + . . . + yb) where a total of a+b integers are given. Our task is to split these integers into two groups, one with a numbers and the other with b numbers, and calculate the product of their sums. By trying ... Read More

C++ Program to Perform Optimal Paranthesization Using Dynamic Programming

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

202 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

Advertisements