Skip to content

Tag Archives: DFS

Given a Tree consisting of N vertices, rooted at vertex 1 and an array val[] representing the values assigned to each vertex, and an array… Read More
Given a Tree, the task is to find the farthest node from each node to another node in the given tree. Examples   Input:  Output: 2… Read More
Given a rooted tree having N vertices, an array values[ ], which represents the value assigned to each node, and a vertex V, the task… Read More
Given an N-ary Tree rooted at 1, and an array val[] consisting of weights assigned to every node, and a matrix Q[][], consisting of queries… Read More
Given a Directed Graph consisting of N vertices and M edges and a set of Edges[][], the task is to check whether the graph contains… Read More
Given a graph of N Nodes and E edges in form of {U, V, W} such that there exists an edge between U and V… Read More
Given two integers V and E representing the number of vertices and edges of an undirected graph G(V, E), a list of edges EdgeList, and… Read More
Given an Undirected Graph consisting of N vertices and M edges, where node values are in the range [1, N], and vertices specified by the… Read More
Given a Directed graph of N vertices and M edges, the task is to find the minimum number of edges required to make the given… Read More
Given an un-directed and unweighted connected graph, find a simple cycle in that graph (if it exists). Simple Cycle: A simple cycle is a cycle… Read More
Given a tree with N nodes numbered from 1 to N and N – 1 edge and array colours[] where colours[i] denote the color of… Read More
Given a Undirected Weighted Tree having N nodes and E edges. Given Q queries, with each query indicating a starting node. The task is to… Read More
Given an undirected graph and two vertices X and Y, our task is to check whether the vertex X lies in the subgraph of the… Read More
Prerequisites:  Diameter of a N-ary tree Path between two nodes in a graph Given a N-ary tree with N nodes numbered from 0 to N-1… Read More
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