Found 7347 Articles for C++

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

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

529 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

439 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

755 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

541 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

156 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

278 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

100 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

207 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

Advertisements