Category Archives: Graph

Minimum steps to reach target by a KnightFebruary 19, 2017

Given a square chessboard of N x N size, the position of Knight and position of a target is given. We need to find out… Read More »

Reverse Delete Algorithm for Minimum Spanning TreeFebruary 18, 2017

Reverse Delete algorithm is closely related to Kruskal’s algorithm. In Kruskal’s algorithm what we do is : Sort edges by increasing order of their weights.… Read More »

Check if removing a given edge disconnects a graph

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 »

Total number of Spanning Trees in a GraphFebruary 1, 2017

If a graph is a complete graph with n vertices, then total number of spanning trees is n(n-2) where n is the number of nodes… Read More »

Chinese Postman or Route Inspection | Set 1 (introduction)

Chinese Postman Problem is a variation of Eulerian circuit problem for undirected graphs. An Euler Circuit is a closed walk that covers every edge once… Read More »

Hierholzer’s Algorithm for directed graphJanuary 22, 2017

Given a directed Eulerian graph, print an Euler circuit. Euler circuit is a path that traverses every edge of a graph, and the path ends… Read More »

Graph implementation using STL for competitive programming | Set 2 (Weighted graph)January 20, 2017

In Set 1, unweighted graph is discussed. In this post, weighted graph representation using STL is discussed. The implementation is for adjacency list representation of… Read More »

Graph implementation using STL for competitive programming | Set 1 (DFS of Unweighted and Undirected)January 19, 2017

We have introduced Graph basics in Graph and its representations. In this post, a different STL based representation is used that can be helpful to… Read More »

k’th heaviest adjacent node in a graph where each vertex has weightJanuary 9, 2017

Given a positive number k and an undirected graph of N nodes, numbered from 0 to N-1, each having a weight associated with it. Note… Read More »

Check loop in array according to given constraintsJanuary 6, 2017

Given an array arr[0..n-1] of positive and negative numbers we need to find if there is a cycle in array with given rules of movements.… Read More »

Two Clique Problem (Check if Graph can be divided in two Cliques)December 19, 2016

A Clique is a subgraph of graph such that all vertcies in subgraph are completely connected with each other. Given a Graph, find if it… Read More »

Minimum Product Spanning TreeDecember 12, 2016

Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices together.… Read More »

Minimum Cost Path with Left, Right, Bottom and Up moves allowedDecember 9, 2016

Given a two dimensional grid, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find… Read More »

Find if an array of strings can be chained to form a circle | Set 2December 7, 2016

Given an array of strings, find if the given strings can be chained to form a circle.

Minimum number of operation required to convert number x into yNovember 23, 2016

Given a initial number x and two operations which are given below: Multiply number by 2. Subtract 1 from the number. The task is to… Read More »