Programming Articles - Page 2672 of 3366

C++ Program to Perform Baillie-PSW Primality Test

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

624 Views

The Baillie-PSW Primality Test, this test named after Robert Baillie, Carl Pomerance, John Selfridge, and Samuel Wagstaff. It is a test which tests whether a number is a composite number or possibly prime.AlgorithmMillerTest()Begin    Declare a function MillerTest of Boolean type.    Declare MT_dt and MT_num of integer datatype and pass as the parameter.    Declare MT_a and MT_x of integer datatype.       Initialize MT_a = 2 + rand( ) % (MT_num - 4).       Initialize MT_x = pow(MT_a, MT_dt, MT_num).    if (MT_x == 1 || MT_x == MT_num - 1) then       ... Read More

C++ Program to Implement the Solovay-Strassen Primality Test to Check if a Given Number is Prime

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

335 Views

Solovay-Strassen Primality Test is used to test a number whether it is a composite or possibly prime number.AlgorithmsBegin    Declare a function modulo to the long datatype to perform binary calculation.       Declare m_base, m_exp, m_mod of long datatype and pass them as a parameter.       Declare two variables a, b of long datatype.          Initialize a = 1, b = m_base.       while (m_exp > 0) do          if (m_exp % 2 == 1) then             a = (a * b) % ... Read More

C++ Program to Find the Vertex Connectivity of a Graph

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

736 Views

To find the Vertex Connectivity of a graph we need to find out Articulation Points of that graph. Articulation Points (or Cut Vertices) in a Graph is a point iff removing it (and edges through it) disconnects the graph. An articulation point for a disconnected undirected graph, is a vertex removing which increases number of connected components.AlgorithmBegin    We use dfs here to find articulation point:    In DFS, a vertex w is articulation point if one of the following two conditions is satisfied.    1) w is root of DFS tree and it has at least two children.   ... Read More

C++ Program to Find the Maximum Cut in a Graph

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

609 Views

In this program to find the maximum Cut in a graph, 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 ... Read More

C++ Program to Find the Connected Components of an UnDirected Graph

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

907 Views

Weakly or Strongly Connected for a given a undirected graph can be found out using DFS. This is a C++ program of this problem.Functions usedBegin Function fillorder() = fill stack with all the vertices.    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex    c) All vertices reachable from v are processed by now, push v to Stack End Begin Function DFS() :    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex EndExample#include ... Read More

C++ Program to Find Strongly Connected Components in Graphs

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

695 Views

Weakly or Strongly Connected for a given a directed graph can be found out using DFS. This is a C++ program of this problem.Functions usedBegin Function fillorder() = fill stack with all the vertices.    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex    c) All vertices reachable from v are processed by now, push v to Stack End Begin Function DFS() :    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex EndExample#include ... Read More

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

220 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

418 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

Advertisements