Back to course home
0% completed
Vote For New Content
Elaborate time complexity
krishnakeshav.pes
Jun 17, 2023
complexity to traverse matrix in O(mxn) and then bfs/dfs is performed on each cell. But we only visit each cell once so, let's say average length is x and no. of islands is y. So, the complexity will be O(x * y) for bfs/dfs. Thus, overall complexity will be O(mnxy).
Can you please help me understand how complexity is being calculated here ?
0
0
Comments
Comments
Shubham Voraa year ago
Here, xy < MN, and we use the below line of code to mark cell as visited. So, each cell will be visited only once.
matrix[x][y] = 0; // mark the cell visited by making it a water cell
On this page
Problem Statement
Try it yourself