Given a weighted graph consisting of N nodes and M edges, a source vertex, a destination vertex, and an integer K, the task is to… Read More

# Tag Archives: DFS

Given a binary matrix mat[][] that represents the adjacency matrix representation of a graph, where mat[i][j] as 1 represents that there is an edge between… Read More

Given a 2D array Edges[][], representing a directed edge between the pair of nodes in a Directed Acyclic Connected Graph consisting of N nodes valued… Read More

Given a 2D array grid[][] of dimension N * M, the task is to perform the Depth – First Search traversal on the given 2D… Read More

Given an N-ary tree consisting of N nodes having values 0 to (N – 1), the task is to find the total number of subtrees… Read More

Given a Binary Tree consisting of N nodes, valued from 1 to N, rooted at node 1, the task is for each node is to… Read More

Given an undirected graph consisting of V vertices and a 2d array E[][2] denoting edges between pairs of nodes. Given another array arr[] representing values… Read More

Given an N-ary Tree consisting of N nodes valued from [1, N], where node 1 is the root, the task is to count the pairs… Read More

Given a 2D array arr[][] consisting of N pairs of integers such that the two elements in each row indicates that they are adjacent elements… Read More

Given an undirected graph G with vertices numbered in the range [1, N] and an array Edges[][] consisting of M edges, the task is to… Read More

Given an integer N, denoting the number of computers connected by cables forming a network and a 2D array connections[][], with each row (i, j)… Read More

Given two arrays Node_ID[] and Parent_ID[]., construct a binary tree where value of ith node is equal to Node_ID[i] and parent of ith node is… Read More

Given a Generic Tree consisting of N nodes (rooted at 0) where each node is associated with a value, the task for each level of… Read More

Given a matrix grid[][] with dimension M × N of integers, the task is to print the matrix elements using DFS traversal. Examples: Input: mat[][]… Read More

Given a Binary Tree and an integer target, denoting the value of a node, the task is to find the sum of distances of all… Read More