Tag Archives: graph-connectivity

Number of cyclic elements in an array where we can jump according to valueNovember 5, 2017

Given a array arr[] of n integers. For every value arr[i], we can move to arr[i] + 1 clockwise considering array elements in cycle. We… Read More »

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 »

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 »

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 »

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 given directed graph is strongly connected | Set 2 (Kosaraju using BFS)February 21, 2017

Given a directed graph, find out whether the graph is strongly connected or not. A directed graph is strongly connected if there is a path… Read More »

Check if removing a given edge disconnects a graphFebruary 18, 2017

Given an undirected graph and an edge, the task is to find if the given edge is a bridge in graph, i.e., removing the edge… Read More »

Maximum edges that can be added to DAG so that is remains DAGNovember 10, 2016

A DAG is given to us, we need to find maximum number of edges that can be added to this DAG, after which new graph… Read More »

Find all reachable nodes from every node present in a given setOctober 8, 2016

Given an undirected graph and a set of vertices, find all reachable nodes from every vertex present in the given set. Consider below undirected graph… Read More »

Find the number of Islands | Set 2 (Using Disjoint Set)June 27, 2016

Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5… Read More »

Find a Mother Vertex in a GraphMarch 28, 2016

What is a Mother Vertex? A mother vertex in a graph G = (V,E) is a vertex v such that all other vertices in G… Read More »

Find k-cores of an undirected graphMarch 26, 2016

Given a graph G and an integer K, K-cores of the graph are connected components that are left after all vertices of degree less than… Read More »

Connected Components in an undirected graphJune 12, 2015

Given an undirected graph, print all connected components line by line. For example consider the following graph.

Karger’s algorithm for Minimum Cut | Set 1 (Introduction and Implementation)May 21, 2015

Given an undirected and unweighted graph, find the smallest cut (smallest number of edges that disconnects the graph into two components).

Assign directions to edges so that the directed graph remains acyclicApril 13, 2015

Given a graph with both directed and undirected edges. It is given that the directed edges don’t form cycle. How to assign directions to undirected… Read More »