# Category Archives: Graph

## Number of groups formed in a graph of friendsOctober 22, 2017

Given n friends and their friendship relations, find the total number of groups that exist. And the number of ways of new groups that can… Read More »

## BFS using STL for competitive codingOctober 20, 2017

A STL based simple implementation of BFS using queue and vector in STL. The adjacency list is represented using vectors of vector. In BFS, we… Read More »

## Comparison of Dijkstra’s and Floyd–Warshall algorithmsOctober 19, 2017

Main Purposes: Dijkstra’s Algorithm is one example of a single-source shortest or SSSP algorithm, i.e., given a source vertex it finds shortest path from source… Read More »

## Cycles of length n in an undirected and connected graphOctober 15, 2017

Given an undirected and connected graph and a number n, count total number of cycles of length n in the graph. A cycle of length… Read More »

## Minimum cost to connect weighted nodes represented as arrayOctober 13, 2017

Given an array of N elements(nodes), where every element is weight of that node.Connecting two nodes will take a cost of product of their weights.You… Read More »

## Detecting negative cycle using Floyd WarshallOctober 12, 2017

We are given a directed graph. We need compute whether the graph has negative cycle or not. A negative cycle is one in which the… Read More »

## Detect a negative cycle in a Graph | (Bellman Ford)

We are given a directed graph. We need compute whether the graph has negative cycle or not. A negative cycle is one in which the… Read More »

## Count single node isolated sub-graphs in a disconnected graphOctober 3, 2017

A disconnected Graph with N vertices and K edges is given. The task is to find the count of singleton sub-graphs. A singleton graph is… Read More »

## DFS for a n-ary tree (acyclic graph) represented as adjacency listSeptember 22, 2017

A tree consisting of n nodes is given, we need to print its DFS. Examples : Input : Edges of graph 1 2 1 3… Read More »

## Maximum number of edges to be added to a tree so that it stays a Bipartite graphSeptember 21, 2017

A tree is always a Bipartite Graph as we can always break into two disjoint sets with alternate levels. In other words we always color… Read More »

## A Peterson Graph ProblemSeptember 19, 2017

The following graph G is called a Petersen graph and its vertices have been numbered from 0 to 9. Some letters have also been assigned… Read More »

## Check if there is a cycle with odd weight sum in an undirected graphSeptember 16, 2017

Given a weighted and undirected graph, we need to find if a cycle exist in this graph such that the sum of weights of all… Read More »

## Check if a graphs has a cycle of odd lengthSeptember 15, 2017

Given a graph, the task is to find if it has a cycle of odd length or not. Recommended: Please try your approach on {IDE}… Read More »

## Implementation of Graph in JavaScriptSeptember 11, 2017

In this article we would be implementing the Graph data structure in JavaScript. Graph is a non-linear data structure. A graph G contains a set… Read More »

## Erdos Renyl Model (for generating Random Graphs)September 3, 2017

In graph theory, the Erdos–Rényi model is either of two closely related models for generating random graphs. There are two closely related variants of the… Read More »