Tag: BFS

Count the number of islands

Given a binary matrix where 0 represents water and 1 represents land, count the number of islands in it. A island is formed by connected one’s.   For example, consider below image.    Above image highlights water in blue and land in grey in a 10 x 10 matrix. There are total five islands present in the above …

Flood Fill Algorithm

Flood fill (also known as seed fill) is an algorithm that determines the area connected to a given node in a multi-dimensional array.

Find shortest safe route in a field with sensors present

Given a rectangular field with few sensors present on it, cross it by taking the shortest safe route without activating the sensors.   The rectangular field is given in the form of M x N matrix and we need to find the shortest path from any cell in first column to any cell in the …

Determine if a given graph is Bipartite Graph or not

Determine if a given graph is Bipartite Graph or not

Given a graph, check if given graph is bipartite graph or not. A bipartite graph (or bigraph) is a graph whose vertices can be divided into two disjoint sets U and V such that every edge connects a vertex in U to one in V.

Breadth First Search (BFS) | Iterative & Recursive Implementation

Breadth first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a ‘search key’) and explores the neighbor nodes first, before moving to the next level neighbors.