Category Archives: Graph

Given a grid grid[][] with 4 types of blocks:  1 represents the starting block. There is exactly one starting block. 2 represents the ending block.… Read More
Given an undirected graph with multiple connected components, the task is to clone the graph. Cloning a graph with a single connected component can be… Read More
Given a starting position ‘k’ and two jump sizes ‘d1’ and ‘d2’, our task is to find the minimum number of jumps needed to reach… Read More
Given an adjacency list representation of a directed graph, the task is to find the path from source to every other node in the graph… Read More
Given a permutation P = p1, p2, …., pn of first n natural numbers (1 ≤ n ≤ 10). One can swap any two consecutive… Read More
Depth First Search (DFS) marks all the vertices of a graph as visited. So for making DFS useful, some additional information can also be stored.… Read More
Given a binary matrix of size NxN where 1 denotes that the number i can be converted to j, and 0 denotes it cannot be… Read More
Given a directed graph, the task is to count the in and out degree of each vertex of the graph.Examples: Input: Output: Vertex In Out… Read More
Graph : A graph is collection of two sets V and E where V is a finite non-empty set of vertices and E is a… Read More
Given a graph G, the task is to check if it represents a Star Topology.A Star Topology is the one shown in the image below: … Read More
Given a graph G, the task is to check if it represents a Ring Topology.A Ring Topology is the one shown in the image below:  … Read More
Given a tree, where each vertex V has a value A[V] stored in it. The task is to find the minimum number of operations required… Read More
Given a graph G, check if it represents a Bus Topology.A Bus Topology is the one shown in the image below:   Examples:   Input: Output: YES… Read More
The relabel-to-front algorithm is used to find the maximum flow in the network. The relabel-to-front algorithm is more efficient than the generic push-relabel method. In… Read More
Prerequisite: Dijkstra’s shortest path algorithm Given an adjacency matrix graph representing paths between the nodes in the given graph. The task is to find the shortest… Read More