# Category Archives: Graph

## Print nodes having maximum and minimum degrees

Given an undirected graph having N nodes, the task is to print the nodes having minimum and maximum degree. Examples: Input: 1—–2 | | 3—–4… Read More »

## Widest Path Problem | Practical application of Dijkstra’s Algorithm

It is highly recommended to read Dijkstra’s algorithm using the Priority Queue first. Widest Path Problem is a problem of finding a path between two… Read More »

## Convert Directed Graph into a Tree

Given an array arr[] of size N. There is an edge from i to arr[i]. The task is to convert this directed graph into tree… Read More »

## Find the minimum number of moves to reach end of the array

Given an array arr[] of size N where every element is from the range [0, 9]. The task is to reach the last index of… Read More »

## Find if a degree sequence can form a simple graph | Havel-Hakimi Algorithm

Given a sequence of non-negative integers arr[], the task is to check if there exists a simple graph corresponding to this degree sequence. Note that… Read More »

## Print all neighbour nodes within distance K

Given a graph of N nodes, E edges, a node X and a distance K. The task is to print all the nodes within the… Read More »

## Check if a cycle of length 3 exists or not in a graph that satisfy a given condition

Given an array Arr of N integers representing the nodes of a graph. The edges are defined between those pair whose bitwise AND is not… Read More »

## Shortest cycle in an undirected unweighted graph

Given an undirected unweighted graph. The task is to find the length of the shortest cycle in the given graph. If no cycle exists print… Read More »

## Check which player visits more number of Nodes

Given a tree with N nodes. Two players A and B start from node 1 and node N respectively. A can visit all the adjacent… Read More »

## Print the path between any two nodes of a tree | DFS

Given a tree of distinct nodes N with N-1 edges and a pair of nodes P. The task is to find and print the path… Read More »

## Product of minimum edge weight between all pairs of a Tree

Given a tree with N vertices and N-1 Edges. Let’s define a function F(a, b) which is equal to the minimum edge weight in the… Read More »

## Find the maximum cost path from the bottom-left corner to the top-right corner

Given a two dimensional grid, each cell of which contains integer cost which represents a cost to traverse through that cell. The task is to… Read More »

## Implementing Generic Graph in Java

We have learnt about Generic class in Java. We can also use them to code for Graph in Java. The Graph Class is implemented using… Read More »

## Find the winner of the match | Multiple Queries

Given an array of pairs arr of size N which represents a game situation where the first player wins against the second player. Given multiple… Read More »