Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 626 of 719
666 Views
In this program, we will perform Edge Coloring of a Graph in which we have to color the edges of the graph that no two adjacent edges have the same color. Steps in Example.AlgorithmBegin Take the input of the number of vertices, n, and then number of edges, e, in the graph. The graph is stored as adjacency list. BFS is implemented using queue and colors are assigned to each edge. EndExample#include using namespace std; int n, e, i, j; vector g; vector color; bool v[111001]; void col(int n) { queue q; int c = ... Read More
842 Views
Vertex Cover of a Graph is to find a set of vertices V, such that for every edge connecting M to N in graph, either M or N (or both) are present in V. In this program, we Implement a Heuristic to Find the Vertex Cover of a Graph.AlgorithmBegin 1) Initialize a set S as empty. 2) Take an edge E of the connecting graph Say M and N. 3) Add both vertex to the set S. 4) Discard all edges in the graph with endpoints at M or N. 5) If some edge is ... Read More
455 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
554 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
2K+ 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
982 Views
In this article, we will learn how to find a path between two nodes in an undirected graph and implement it in C++. We will represent graph as an adjacency list and use a depth-first search (DFS) algorithm to find the path. We already discussed finding a path between two nodes in a directed graph, check here. Finding Path Between Two Nodes in an Undirected Graph We have an adjacency list representation of an undirected graph adj[] and two nodes src and dest, our task is to write a program that finds the path between the src ... Read More
623 Views
An articulation point is a vertex of the graph, which when removed, will break the graph into two or more components. You are given a connected undirected graph with V vertices and E edges. Your task is to find number of articulation points in the graph. To understand this better, consider the following example: Graph: 0 / \ 1 - 2 | 3 - 4 Output: 2 Articulation Points Explanation: Removing vertex 1 or 3 will split the graph into two components. Methods to Find Articulation Points To ... Read More
659 Views
The chromatic index of a graph is the maximum number of color needed for the edge coloring of the graph, such that no two adjacent edges have the same color. It is also known as the edge chromatic number. A cyclic graph is a graph that contains at least one cycle or a closed path. For example, a triangle is a cyclic graph and we can color its edges with 3 colors. // Graph: 0 -> 1 1 -> 2, 3 2 -> 0 Chromatic Index: 3 To find the chromatic index of cyclic graphs, we ... Read More
295 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
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