Found 7197 Articles for C++

C++ Program to Check Whether it is Weakly Connected or Strongly Connected for a Directed Graph

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

288 Views

Weakly or Strongly Connected for a given a directed graph can be find 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 ... Read More

C++ Program to Check Whether a Hamiltonian Cycle or Path Exists in a Given Graph

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

1K+ 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 purposes:Begin    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 Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph

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

1K+ Views

Topological sorting of DAG (Directed Acyclic Graph) is a linear ordering of vertices such that for every directed edge uv, where vertex u comes before v in the ordering. If the graph is not a DAG, Topological Sorting for a graph is not possible.Functions and pseudocodesBegin    function topologicalSort():    a) Mark the current node as visited.    b) Recur for all the vertices adjacent to this vertex.    c) Push current vertex to stack which stores result. End Begin    function topoSort() which uses recursive topological sort() function:    a) Mark all the vertices which are not visited.   ... Read More

C++ Program to Find Inverse of a Graph Matrix

Farhan Muhamed
Updated on 16-Jul-2025 16:24:13

9K+ Views

Every graph can be represented by a matrix called the adjacency matrix, in which each element indicates whether pairs of vertices have an edge between them. In this article, we will learn to find the inverse of a adjacency matrix of a graph using C++. First of all, let's understand what the inverse of a matrix means. Inverse of a Matrix The inverse of a matrix A is another matrix, denoted as A-1, such that the result of matrix multiplication A.A-1 will be an identity matrix I. The identity matrix is a square matrix with ones on the diagonal ... Read More

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

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

272 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

Farhan Muhamed
Updated on 17-Jul-2025 17:17:06

803 Views

The Breadth First Search (BFS) algorithm can be used to check whether a graph is bipartite by coloring the graph using two colors. This section will discuss how the BFS traversal can be used to check if a graph is bipartite. First of all, let's understand what a bipartite graph is. What is Bipartite Graph? Bipartite graph is special graph where you can divide the vertices into two sets, such that no two vertices of the same set are connected. This is why, it's possible to color a bipartite graph by using just two colors. Technically a graph is ... Read More

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

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

258 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

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

Akansha Kumari
Updated on 11-Jun-2025 18:01:43

9K+ Views

In this article, we will see how to get the Host name and IP address of the local system in an easier way using C and C++ program.  Getting IP Address of Local Computer For this, some standard networking functions are available in socket programming with header files like on Windows and , , on Linux. In this article we will mainly discuss three commonly used functions: Sr.No ... Read More

C/C++ Struct vs Class

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

420 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++

Akansha Kumari
Updated on 09-Jun-2025 15:28:49

37K+ Views

The main() function in C and C++ is anentry point of a program from where the execution begins. And there are two common ways available to define the main function; int main() and void main(). In this following article we will learn the differences between these two in detail. The main() function is the same like other functions, which takes arguments and returns some value. A point to keep in mind is that the execution of a program always begins from the main() function. When a program runs, the operating system calls the main() and the value returned from it ... Read More

Advertisements