Found 7346 Articles for C++

C++ Program to Check whether Graph is a Bipartite using DFS

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

184 Views

A bipartite graph is a graph in which if the graph coloring is possible using two colors i.e.; vertices in a set are colored with the same color. This is a C++ program to Check whether a graph bipartite or not using DFS.AlgorithmBegin    1. An array color[] is used to stores 0 or 1 for every node which denotes opposite colors.    2. Call function DFS from any node.    3. If the node w has not been visited previously, then assign !       color[v] to color[w] and call DFS again to visit nodes connected to w. ... Read More

C++ Program to Check whether Graph is a Bipartite using BFS

Paul Richard
Updated on 30-Jul-2019 22:30:25

605 Views

A bipartite graph is a graph in which if the graph coloring is possible using two colors i.e; vertices in a set are colored with the same color. This is a C++ program to Check whether a graph bipartite or not using BFS.AlgorithmBegin    Function Bipartite():    1) Assign a color to the source vertex    2) Color all the neighbors with another color except first one color.    3) Color all neighbor’s neighbor with First color.    4) Like this way, assign color to all vertices such that it satisfies all the constraints of k way coloring problem where ... Read More

C++ Program to Check whether Graph is a Bipartite using 2 Color Algorithm

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

217 Views

A bipartite graph is a graph in which if the graph coloring is possible using two colors i.e.; vertices in a set are colored with the same color. This is a C++ program to Check whether a graph bipartite or not using 2 color algorithm.Functions and pseudocodesBegin    1. Develop function isSafe() to check if the current color assignment       is safe for vertex v, i.e. checks whether the edge exists or not.       If it exists, then next check whether the color to be filled in       the new vertex is already used ... Read More

C++ Program to Find the Transitive Closure of a Given Graph G

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

185 Views

If a directed graph is given, determine if a vertex j is reachable from another vertex i for all vertex pairs (i, j) in the given graph. Reachable mean that there is a path from vertex i to j. This reach-ability matrix is called transitive closure of a graph. Warshall algorithm is commonly used to find the Transitive Closure of a Given Graph G. Here is a C++ program to implement this algorithm.AlgorithmBegin    1. Take maximum number of nodes as input.    2. For Label the nodes as a, b, c…..    3. To check if there any edge ... Read More

C++ Program to Remove the Edges in a Given Cyclic Graph such that its Linear Extension can be Found

George John
Updated on 30-Jul-2019 22:30:25

177 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 ... Read More

C++ Program to Check if a Directed Graph is a Tree or Not Using DFS

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

188 Views

A graph is a tree if it does not contain any cycle. This is a C++ program to check whether a directed graph is tree or not using DFS.AlgorithmBegin function cyclicUtil() :    a) Mark the current node as visited and part of recursion stack    b) Recur for all the vertices adjacent to this vertex.    c) Remove the vertex from recursion stack. function cyclic() :    a) Mark all the vertices as not visited and not part of recursion stack    b) Call the CyclicUtill() function to detect cycle in different trees EndExample#include #include #include using ... Read More

C++ Program to Check if an UnDirected Graph is a Tree or Not Using DFS

George John
Updated on 30-Jul-2019 22:30:25

163 Views

A graph is a tree if it does not contain any cycle. This is a C++ program to check whether an undirected graph is tree or not.AlgorithmBegin function cyclicUtil() :    A) Mark the current node as visited.    B) Recur for all the vertices adjacent to this vertex.    C) If an adjacent is not visited, then recur for that adjacent.    D) If an adjacent is visited and not parent of current vertex, then there is a cycle. End Begin function cyclic():    A) Mark all the vertices as not visited and not part of recursion stack.   ... Read More

How to get the IP Address of local computer using C/C++?

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

7K+ Views

In this section we will see how to see the Host name and IP address of the local system in an easier way. We will write a C program to find the host name and IP.Some of the following functions are used. These functions have different task. Let us see the functions and their tasks.Sr.NoFunction & Description1gethostname()It finds the standard host name for the local computer.2gethostbyname()It finds the host information corresponding to a host name from host database3iten_ntoa()It converts an IPv4 Internet network address into an ASCII string into dotted decimal format.Example#include #include #include #include #include ... Read More

C/C++ Struct vs Class

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

287 Views

In C++ the structure and class are basically same. But there are some minor differences. These differences are like below.The class members are private by default, but members of structures are public. Let us see these two codes to see the differences.Example#include using namespace std; class my_class {    int x = 10; }; int main() {    my_class my_ob;    cout

Difference between void main and int main in C/C++

Nishtha Thakur
Updated on 13-Sep-2023 15:36:59

32K+ Views

Sometimes we use int main(), or sometimes void main(). Now the question comes into our mind, that what are the differences between these two.The main() function is like other functions. It also takes arguments, and returns some value. One point we have to keep in mind that the program starts executing from this main() function. So the operating system calls this function. When some value is returned from main(), it is returned to operating system.The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data. ... Read More

Advertisements