Question: (Graph Traversal) Given a n*n grid of square; each square can be 1 (land) or 0 (water). An island is a maximally connected land square;
(Graph Traversal)
Given a n*n grid of square; each square can be 1 (land) or 0 (water). An island is a maximally connected land square; two land square are connected if they have common edges.
Find the number of islands for the given grid of squares
// Starter Code
#include
#include
#include
#include
usingnamespacestd;
intmain()
{
intn;
cin>>n;
cout<<"n="< vector for(inti=0;i for(intj=0;j cin>>grid[i][j]; } } intcnt=0; //nowcounthowmanyislands! cout< return0; } Please help complete the above code using graph traversal. Please include commenting and explanations of the code to help me understand how the solution was reached. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
