- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
![Paul Richard](https://www.tutorialspoint.com/assets/profiles/13505/profile/60_52698-1512536733.jpg)
323 Views
This is C++ Program to Generate All Subsets of a Given Set in the Lexico Graphic Order. This algorithm prints all the possible combination of each length from the given set of array in increasing order. The time complexity of this algorithm is O(n*(2^n)).AlgorithmBegin For each length ‘i’ GenAllSubset() function is called: 1) In GenAllSubset(), if currLen is more than the reqLen then return. 2) Otherwise, if currLen is equal to reqLen then there will be a new sequence generated, print it. 3) If proceed with a start as ‘true’ and recursively call GenAllSubset() with incremented ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
438 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 pseudocode:Begin 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
1K+ Views
This is a C++ program to find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs) using Dijkstra Algorithm to find out from the first node in graph to every other node with the shortest path length showed beside each pair of vertices.AlgorithmBegin Take the elements of the graph as input. function shortestpath(): Initialize the variables a[i] = 1 d[i] = 0 s[i].from = 0 Initialize a loop for i = 0 to 3 do if b[0][i] == 0 continue else ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
657 Views
In this Program we can find out whether path exists between two nodes by using DFS on given graph.AlgorithmBegin 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 ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
413 Views
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. 2) w is not root of DFS tree and it has a child x such that no vertex ... Read More
![Paul Richard](https://www.tutorialspoint.com/assets/profiles/13505/profile/60_52698-1512536733.jpg)
433 Views
The chromatic index is the maximum number of color needed for the edge coloring of the given graph. This is a C++ Program to Find Chromatic Index of Cyclic Graphs.AlgorithmBegin Take the input of the number of vertices ‘n’ and number of edges ‘e’. Take the input of ‘e’ vertex pairs for the ‘e’ edges in the graph in edge[][]. Function ChromaticIndex(), Color the graph edges: A) assign color to current edge as c. B) If any of the adjacent edges have the same color then discard this color and go to flag again and ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
194 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
![Paul Richard](https://www.tutorialspoint.com/assets/profiles/13505/profile/60_52698-1512536733.jpg)
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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
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
![Paul Richard](https://www.tutorialspoint.com/assets/profiles/13505/profile/60_52698-1512536733.jpg)
7K+ Views
This is a C++ program to Find Inverse of a Graph Matrix. Inverse of a matrix exists only if the matrix is non-singular i.e., determinant should not be 0. Inverse of a matrix can find out in many ways. Here we find out inverse of a graph matrix using adjoint matrix and its determinant. Steps involved in the ExampleBegin function INV() to get the inverse of the matrix: Call function DET(). Call function ADJ(). Find the inverse of the matrix using the formula; Inverse(matrix) = ADJ(matrix) / DET(matrix) End.Example#include using namespace std; #define N 5 ... Read More