Found 7347 Articles for C++

C++ Program to Solve the Dominating Set Problem

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

277 Views

This is a C++ program to solve the Dominating Set problem.AlgorithmBegin    Take the number of vertices and edges as input. Also take the edge point of the edges.    function dominant():       Declare vector Set.       Take any edge e graph connecting the vertices i.e.; X and Y.       Add one vertex between X and Y to set s.       Delete all the edges connected to X. EndExample#include using namespace std; vector g; bool visit[10001]; int i, j; vector dominant(int v, int e) {    vector Set;    //Take any edge ... Read More

C++ Program to Find Whether a Path Exists Between 2 Given Nodes

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

222 Views

This is a C++ program to find whether a path exists between 2 given nodesAlgorithmBegin    function isReach() is a recursive function to check whether d is reachable to s:    A) Mark all the vertices as unvisited.    B) Mark the current node as visited and enqueue it and it will be used to get all adjacent vertices of a vertex.    C) Dequeue a vertex from queue and print it.    D) Get all adjacent vertices of the dequeued vertex s.    E) If an adjacent has not been visited, then mark it visited and enqueue it.   ... Read More

C++ Program to Generate All Pairs of Subsets Whose Union Make the Set

Samual Sam
Updated on 30-Jul-2019 22:30:26

166 Views

This is a C++ program to generate all pairs of subsets, whose union make the Set.AlgorithmsBegin    function UnionSet():    Arguments:       a[] = an array.       n = number of elements.       Body of the function:       1) Generate binary code from 0 to 2^(n-1)-1 for all 2^(n-1) pairs.       2) Print the array element which has 0 or 1 in corresponding indexes in code string for each code.       3) Print them in a different set, which on the union of both sets gives the super set. EndExample#include #include #include using namespace std; void display(char code[], int a[], int n) //display the pairs {    int i;    cout

C++ Program to Solve a Matching Problem for a Given Specific Case

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

393 Views

This is a C++ Program to solve a matching problem for a Given Specific Case. Here, N men and N women are given, each person has ranked all members of the opposite gender in order of preference, marry the men and women together such that there are no two people of opposite gender who would both rather have each other than their current partners. All the marriages are “stable”, if there are no such people exists.AlgorithmsBegin    function WomenPrefersMenOverMen1():    A) Check if women prefer men over her current engagement men1    B) If men1 comes before men in list ... Read More

C++ Program to Generate All Possible Combinations Out of a,b,c,d,e

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

3K+ Views

This is a C++ program to generate all possible combinations out of a, b, c, d, e.AlgorithmsBegin    Take the number of elements and the elements as input.    function Combi(char a[], int reqLen, int s, int currLen, bool check[], int l)    to print the all possible combination of given array set:    //    Here,    char a[] = character array    reqLen = required length    s = start variable    currLen = current length    check[] = a boolean variable    l = length of array    //    Body of the Function:       ... Read More

C++ program to Solve Tower of Hanoi Problem using Binary Value

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

243 Views

This C++ program displays the solution to the Tower of Hanoi problem using binary value.There is one binary digit for each disk.The most significant bit represents the largest disk. A value of 0 indicates that the largest disk is on the initial peg, while a 1 indicates that it’s on the final peg.The bitstring is read from left to right, and each bit can be used to determine the location of the corresponding disk.The corresponding disk is stacked on top the previous disk on the same peg if a bit has the same value as the previous one.If it is ... Read More

C++ Program to Generate All Possible Subsets with Exactly k Elements in Each Subset

Samual Sam
Updated on 30-Jul-2019 22:30:26

228 Views

This is a C++ program to generate all possible subsets with exactly k elements in each subset.AlgorithmsBegin    function PossibleSubSet(char a[], int reqLen, int s, int currLen, bool check[], int l):    If currLen > reqLen    Return    Else if currLen = reqLen       Then print the new generated sequence.    If s = l       Then return no further element is left.       For every index there are two options:          either proceed with a start as ‘true’ and recursively call PossibleSubSet()          with incremented value ... Read More

C++ Program to Generate Random Partition out of a Given Set of Numbers or Characters

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

218 Views

This is a C++ program to generate Random Partition out of a given set of numbers or characters.AlgorithmBegin    Take the integers or characters as input.    For choice 1:       Take the input of the n integer array.       Assign l = 0 to traverse the array.       Using rand(), generate random integer partition of n.       For each partition i, print next i integer from index value l.    For choice is 2:       Take the input of a string in ch[].       Calculate the length ... Read More

C++ Program to Generate a Random Subset by Coin Flipping

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

155 Views

This is a C++ program to generate a Random Subset by Coin Flipping.AlgorithmsBegin    Take elements in an array as input.    Using rand(), generate a random binary sequence.    It generates randomly 0 or 1 as coin flipping and print the array element if it is 1. EndExample#include #include using namespace std; int main() {    int i, n;    coutn;    int a[n];    cout

C++ Program to Implement the Binary Counting Method to Generate Subsets of a Set

Samual Sam
Updated on 30-Jul-2019 22:30:26

703 Views

This is a C++ program to implement the Binary Counting Method to generate subsets of a set.AlgorithmsBegin    Take the array elements as input.    function BinaryCounting():       Calculate subset by r = pow(2, n) // here n = number of elements.       Generate binary numbers from 0 to r-1.       Call solution() for each binary string of n character. EndExample#include #include using namespace std; void solution(char code[], int a[], int n) //print the solution {    int i;    cout

Advertisements