# Tag Archives: DFS

## 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 »

## Octal equivalents of connected components in Binary valued graph

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

## Find a Mother vertex in a Graph using Bit Masking

A mother vertex in a Graph G = (V, E) is a vertex v such that a path from v can reach all other vertices… Read More »

## Count of nodes having odd divisors in the given subtree for Q queries

Given a binary tree and Q queries where each query contains a node of the binary tree, the task is to count the number of… Read More »

## Maximum weighted edge in path between two nodes in an N-ary tree using binary lifting

Given an N-ary tree with weighted edge and Q queries where each query contains two nodes of the tree. The task is to find the… Read More »

## Minimum valued node having maximum depth in an N-ary Tree

Given a tree of N nodes, the task is to find the node having maximum depth starting from the root node, taking the root node… Read More »

## Paranthesis Theorem

Parenthesis Theorem is used in DFS of graph. It states that the descendants in a depth-first-search tree have an interesting property. If v is a… Read More »

## Largest subarray sum of all connected components in undirected graph

Given an undirected graph with V vertices and E edges, the task is to find the maximum contiguous subarray sum among all the connected components… Read More »

## Count of elements which form a loop in an Array according to given constraints

Given an array A containing N integers, the task is to count the number of elements which form a cycle in the array, based on… Read More »

## Size of the Largest Trees in a Forest formed by the given Graph

Given an undirected acyclic graph having N nodes and M edges, the task is to find the size of the largest tree in the forest… Read More »

## Minimum time required to visit all the special nodes of a Tree

Given an undirected tree consisting of N vertices where some of the nodes are special nodes, the task is to visit all the special nodes… Read More »

## Minimum string such that every adjacent character of given string is still adjacent

Given a string S, the task is to find the minimum length string such that every adjacent character of the string remains adjacent in the… Read More »

## Count of leaf nodes of the tree whose weighted string is a palindrome

Given an N-ary tree, and the weights which are in the form of strings of all the nodes, the task is to count the number… Read More »

## Find the maximum component size after addition of each edge to the graph

Given an array arr[][] which contains the edges of a graph to be used to construct an undirected graph G with N nodes, the task… Read More »