# Category Archives: Graph

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
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 such… Read More
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
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 islands … Read More
Given a tree (not necessarily a binary tree) and a number of queries such that every query takes two nodes of the tree as parameters.… Read More
Given a rectangular matrix, we can move from current cell in 4 directions with equal probability. The 4 directions are right, left, top or bottom.… Read More
There are two common ways to traverse a graph, BFS and DFS. Considering a Tree (or Graph) of huge height and width, both BFS and… Read More
Given an undirected, connected and weighted graph, find Minimum Spanning Tree (MST) of the graph using Kruskal’s algorithm. Input : Graph as an array of… Read More
Given a MxN matrix where each element can either be 0 or 1. We need to find the shortest path between a given source cell… Read More
Given a graph, a source vertex in the graph and a number k, find if there is a simple path (without any cycle) starting from… Read More
Dijkstra’s shortest path algorithm runs in O(Elog V) time when implemented with adjacency list representation (See C implementation and STL based C++ implementations for details).… Read More
We strongly recommend to refer below article before moving on to this article. Push Relabel Algorithm | Set 1 (Introduction and Illustration) Problem Statement :… Read More
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v… Read More
Given a graph which represents a flow network where every edge has a capacity. Also given two vertices source ‘s’ and sink ‘t’ in the… Read More
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