# Tag Archives: DFS

## Check whether the cost of going from any node to any other node via all possible paths is same

Given adjacency list representation of a directed graph, the task is to check whether the cost of going from any vertex to any other vertex… Read More »

## Count of different groups using Graph

Given a graph with N nodes having values either P or M. Also given K pairs of integers as (x, y) representing the edges in… Read More »

## Construct Binary Tree from Ancestor Matrix | Top Down Approach

Given an ancestor matrix mat[n][n] where the ancestor matrix is defined as below. mat[i][j] = 1 if i is ancestor of j mat[i][j] = 0,… Read More »

## Print all possible paths from the first row to the last row in a 2D array

Given a 2D array of characters with M rows and N columns. The task is to print all the possible paths from top (first row)… Read More »

## Find count of pair of nodes at even distance

Given a connected acyclic graph with N nodes and N-1 edges, find out the pair of nodes that are at even distance from each other.… Read More »

## Print completed tasks at end according to Dependencies

Given N dependencies of the form X Y, where X & Y represents two different tasks. The dependency X Y denotes dependency of the form… 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 »

## Queries for the number of nodes having values less than V in the subtree of a Node

Given a rooted tree (assume root is 1) of N nodes and Q queries, each of the form (Val, Node). For each query, the task… Read More »

## Sum of the distances from every node to all other nodes is maximum

Given a tree with N nodes and N-1 edges with root at 1 and given an array of N-1 integers. The task is to assign… Read More »

## Find K vertices in the graph which are connected to at least one of remaining vertices

Given a connected graph with N vertices. The task is to select k(k must be less than or equals to n/2, not necessarily minimum) vertices… Read More »

## Maximum number of nodes which can be reached from each node in a graph.

Given a graph with N nodes and K bidirectional edges between them find the number of nodes which can be reachable from a particular. Two… Read More »

## Construct the Rooted tree by using start and finish time of its DFS traversal

Given start and finish times of DFS traversal of N vertices that are available in a Rooted tree, the task is to construct the tree… Read More »

## Count the nodes of the tree which make a pangram when concatenated with the sub-tree nodes

Given a tree, and the weights (in the form of strings) of all the nodes, the task is to count the nodes whose weighted string… Read More »

## Count the nodes of a tree whose weighted string is an anagram of the given string

Given a tree, and the weights (in the form of strings) of all the nodes, the task is to count the nodes whose weighted string… Read More »