# Tag Archives: BFS

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 binary tree and a node start that is initially infected. For every second, neighbours of an infected node get infected. The task is… 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 a matrix mat[][] of size N*M and the destination (x, y) to be reached from (0, 0), the task is to find if you… Read More
Given a directed graph with N nodes and M connections shown in the matrix mat[] where each element is of the form {xi, yi} denoting… Read More
Given two integers N and X, the task is to convert 1 to N using minimum operations of any of the following operations: Change a… Read More
Geek is in a maze of size N * M. Each cell in the maze is made of either ‘.’ or ‘#’. An empty cell… Read More
Given a connected acyclic graph with N nodes numbered from 1 to N and N-1 edges, find out the pair of nodes that are at… Read More
Given a grid[][] containing 0s and 1s, where ‘0’ represents water and ‘1’ represents land. Given that an island is a group of land (1s)… Read More
Given a Grid of size NxM, and two integers X and Y, the task is to count the minimum number of rows between the row… Read More
There is an N x M rectangular island that borders both the Pacific Ocean and the Atlantic Ocean. The Pacific Ocean touches the island’s left… Read More
Given a 2D grid arr[][] of ‘W’ and ‘L’ where ‘W’ denotes water and ‘L’ denotes land, the task is to find the minimum number… Read More
Given a perfect binary tree consisting of N nodes, the task is to check if the number formed by the nodes in any level of… Read More
Given a graph G(V, E), divide it into two sets such that no two vertices in a set are connected directly. If not possible print… Read More
Given a numeric string target of length N and a set of numeric strings blocked, each of length N, the task is to find the… Read More