Skip to content

Tag Archives: DFS

Given a tree with N nodes, an array A[] of size N denoting the value of each node and array edges [][] of size (N-1),… Read More
To understand this let’s take a binary tree Binary tree If we conduct BFS in this tree: In level 0 there is one node in… Read More
Given a character matrix consisting of O’s and X’s, find the number of submatrices containing only ‘X’ and surrounded by ‘O’ from all sides.  Examples:… Read More
Given a 2-D array A[][] of size N×3, where each element of the array consists of {x, y, r}, where x and y are coordinates… Read More
Generally, when we come across a graph problem, we might need to traverse the structure of the given graph or tree to find our solution… Read More
Given N tanks connected like a tree, the connections between them in an array Edge[][], and the capacity of each tank in the array cap[],… Read More
Given a directed graph with N nodes and M edges in array V[], the task is to find the number of nodes that are accessible… Read More
Given an undirected tree with N nodes numbered from 1 to N and an array A[] where A[i] denotes the value assigned to (i+1)th node.… Read More
Given two integers N and M, the task is to generate any N * M sized maze containing only 0 (representing a wall) and 1… Read More
Given a tree with N vertices and N-1 edges represented by a 2D array edges[], the task is to find the minimum value among the… Read More
Given a binary tree, a target node and a positive integer K on it,  the task is to find the sum of all nodes within… Read More
Given a tree of N vertices, the task is to find the number of pairs of vertices such that the distance between them is even… Read More
Given, a binary tree, the task is to convert this tree using minimum number of increment-decrement operations into a tree which satisfies the following conditions:… Read More
Given a binary tree, the task is to: Print all the leaf nodes and then delete them all.  Repeat this process till the tree becomes… Read More
Given a tree of having N nodes rooted at node 0, and an array val[] denoting the value at each node, the task is to… Read More

Start Your Coding Journey Now!