# Tag Archives: DFS

## Print all possible paths in a DAG from vertex whose indegree is 0

Given a Directed Acyclic Graph (DAG), having N vertices and M edges, The task is to print all path starting from vertex whose in-degree is… Read More »

## Maximum cost path in an Undirected Graph such that no edge is visited twice in a row

Given an undirected graph having N vertices and M edges and each vertex is associated with a cost and a source vertex S is given.… Read More »

## Count of subtrees from an N-ary tree consisting of single colored nodes

Given a N-ary tree consisting of N nodes and a matrix edges[][] consisting of N – 1 edges of the form (X, Y) denoting the… Read More »

## Sum of minimum element at each depth of a given non cyclic graph

Given a non-cyclic graph having V nodes and E edges and a source node S, the task is to calculate the sum of the minimum… Read More »

## Length of longest connected 1’s in a Binary Grid

Given a grid of size N*M consists of 0 and 1 only, the task is to find the length of longest connected 1s in the… Read More »

## Check if it is possible to reach to the index with value K when start index is given

Given an array arr[] of N positive integers and two positive integers S and K, the task is to reach the position of the array… Read More »

## Smallest number containing all possible N length permutations using digits 0 to D

Given two integer N and K, the task is to find the size of the smallest string that contains all permutations of length N that can… Read More »

## Total number of components in the index Array

Given an array arr[] of N integers of value from 0 to N, the task is to count the number of components in Index Array.… Read More »

## Maximum sum possible for every node by including it in a segment of N-Ary Tree

Given an N-Ary tree containing N nodes and an array weight [ ] that denotes the weight of the nodes which can be positive or… Read More »

## Count of node sequences of length K consisting of at least one black edge

Given a tree consisting of N nodes numbered from [1, N] and is coloured either black(denoted by 1) or green(denoted by 0), the task is… Read More »

## Hexadecimal equivalents in Binary Valued Graph

Given a binary valued undirected graph with V vertices and E edges, the task is to find the hexadecimal equivalents of all the connected components… Read More »

## Maximize sum of minimum difference of divisors of nodes in N-ary tree

Given a n-ary tree having nodes with a particular weight, our task is to find out the maximum sum of the minimum difference of divisors… Read More »

## Find GCD of each subtree of a given node in an N-ary Tree for Q queries

Given an N-ary Tree containing N nodes, values associated with each node and Q queries, where each query contains a single node. The task is… Read More »

## Count of distinct colors in a subtree of a Colored Tree with given min frequency for Q queries

Given a N-ary tree with some colour associated with every node and Q queries. Each query contains two integers A and X. The task is… Read More »

## Find dependencies of each Vertex in a Directed Graph

Given a directed graph containing N vertices and M edges, the task is to find all the dependencies of each vertex in the graph and… Read More »