Found 7197 Articles for C++

How to write a short literal in C++?

Akansha Kumari
Updated on 15-Jul-2025 17:35:04

976 Views

In the following article, we will learn about short literals in C++. In both C and C++, different data types have different literals. A literal is a fixed constant value, which is assigned to the variables of different data types. For example, here is a list of different data types with their literals. Datatypes Literals ... Read More

C++ Program to Perform Edge Coloring on Complete Graph

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

330 Views

A complete graph is a graph which has a connecting edge between any pair of vertices. This is a C++ Program to Perform Edge Coloring on Complete Graph.AlgorithmBegin    Take the input of the number of vertices ‘n’.    Construct a complete graph using e=n*(n-1)/2 edges, in ed[][].    Function EdgeColor() is used to Color the graph edges.    A) Assign color to current edge as c i.e. 1 initially.    B) If the same color is occupied by any of the adjacent edges, then       discard this color and go to flag again and try next color. ... Read More

C++ Program to Perform Edge Coloring of a Graph

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

653 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

C++ Program to Implement a Heuristic to Find the Vertex Cover of a Graph

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

826 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

C++ Program to Generate All Subsets of a Given Set in the Lexico Graphic Order

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

444 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

C++ Program to Find the Edge Connectivity of a Graph

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

542 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

C++ Program to Find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs)

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

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

C++ Program to Find Path Between Two Nodes in a Graph

Farhan Muhamed
Updated on 30-Jul-2025 15:36:29

938 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

C++ Program to Find Number of Articulation points in a Graph

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

592 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

C++ Program to Find Chromatic Index of Cyclic Graphs

Farhan Muhamed
Updated on 16-Jul-2025 18:20:22

646 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

Advertisements