# Category Archives: Graph

## Minimum edges to reverse to make path from a source to a destinationNovember 11, 2016

Given a directed graph and a source node and destination node, we need to find how many edges we need to reverse in order to… 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 »

## Minimum steps to reach end of array under constraintsNovember 6, 2016

Given an array containing one digit numbers only, assuming we are standing at first index, we need to reach to end of array using minimum… Read More »

## Find the smallest binary digit multiple of given number

A decimal number is called binary digit number if its digits are binary. For example, 102 is not a binary digit number and 101 is.… Read More »

## Check whether given degrees of vertices represent a Graph or TreeNovember 4, 2016

Given the number of vertices and the degree of each vertex where vertex numbers are 1, 2, 3,…n. The task is to identify whether it… Read More »

## Longest path between any pair of verticesOctober 17, 2016

We are given a map of cities connected with each other via cable lines such that there is no cycle between any two cities. We… Read More »

## Roots of a tree which give minimum heightOctober 13, 2016

Given an undirected graph, which has tree characteristics. It is possible to choose any node as root, the task is to find those nodes only… 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 »

Given two integers ‘n’ and ‘m’, find all the stepping numbers in range [n, m]. A number is called stepping number if all adjacent digits… Read More »

## Clone an Undirected GraphSeptember 2, 2016

Cloning of a LinkedList and a Binary Tree with random pointers has already been discussed. The idea behind cloning a graph is pretty much similar.… Read More »

## Longest Path in a Directed Acyclic Graph | Set 2August 28, 2016

Given a Weighted Directed Acyclic Graph (DAG) and a source vertex in it, find the longest distances from source vertex to all other vertices in… Read More »

## Find Shortest distance from a guard in a BankAugust 26, 2016

Given a matrix that is filled with ‘O’, ‘G’, and ‘W’ where ‘O’ represents open space, ‘G’ represents guards and ‘W’ represents walls in a… Read More »

## Topological Sort of a graph using departure time of vertexAugust 24, 2016

Given a Directed Acyclic Graph (DAG), find Topological Sort of the graph. Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices… Read More »

## Finding minimum vertex cover size of a graph using binary searchJuly 5, 2016

A vertex cover of an undirected graph is a subset of its vertices such that for every edge (u, v) of the graph, either ‘u’… 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 »