0% completed
Space complexity of DFS solution might be incorrectly given
Anand Mohan
Aug 27, 2023
Given :
DFS recursion stack can go deep when the whole matrix is filled with '1's. Hence, the space complexity will be , where ‘M’ is the number of rows and 'N' is the number of columns of the input matrix.
All the matrix element will not be in one recursion stack. It will part of call back to left and right sub-path. So, the space complexity should be less then (M*N)
I think for DFS as well the Space Complexity would be O(min(M, N))
Please correct me If I am wrong.
0
0
Comments
cookies 2 years ago
Ya I'm confused by this as well because if we look at the section, Solution: 0/1 Knapsack, they say that
"The space complexity is O(n). This space will be used to store the recursion stack. Since the recursive algorithm works in a depth-first fashion, which means th...
Manuel9 months ago
Really disappointed they dont fix their stuff over a year
Manuel9 months ago
I Just got a good explanation from DeepSeek:
Time Complexity
- Outer Loop:
- The outer loop iterates over each cell in the
matrix. If the matrix hasrowsandcols, the total number of cells isrows * cols. - This gives us a time complexity o...
- The outer loop iterates over each cell in the
On this page