Maximum size square sub-matrix with all 1s
Given a matrix of dimensions mxn having all entries as 1 or 0, find out the size of maximum size square sub-matrix with all 1s.
Algorithm:
1: Create an empty table of size mxn, defined as
table[i][j] = Size of maximum square sub matrix with all 1s with matrix[i][j] as bottom right element.
2: Set values in table based on the conditions
a: if i = 0 or j = 0, table[i][j] = matrix[i][j]
b: else if matrix[i][j] = 0 then table[i][j] = 0
c: else table[i][j] = min(table[i - 1][j - 1], table[i - 1][j], table[i][j - 1]) + 1;
During step 2, maintain largest element added in the table and finally return it.
Order of the Algorithm:
Time Complexity: O(mn)
Space Complexity: O(mn)
Code and Algorithm Visualization: http://www.ideserve.co.in/learn/maximum-size-square-sub-matrix-with-all-1s
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Maximum size square sub-matrix with all 1s канала IDeserve
Algorithm:
1: Create an empty table of size mxn, defined as
table[i][j] = Size of maximum square sub matrix with all 1s with matrix[i][j] as bottom right element.
2: Set values in table based on the conditions
a: if i = 0 or j = 0, table[i][j] = matrix[i][j]
b: else if matrix[i][j] = 0 then table[i][j] = 0
c: else table[i][j] = min(table[i - 1][j - 1], table[i - 1][j], table[i][j - 1]) + 1;
During step 2, maintain largest element added in the table and finally return it.
Order of the Algorithm:
Time Complexity: O(mn)
Space Complexity: O(mn)
Code and Algorithm Visualization: http://www.ideserve.co.in/learn/maximum-size-square-sub-matrix-with-all-1s
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Maximum size square sub-matrix with all 1s канала IDeserve
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Maximal square | Dynamic programming | Leetcode #221Shortest Range in K sorted listsMaximum Size Rectangle of All 1's Dynamic ProgrammingMaximum size square sub-matrix with all 1s | GeeksforGeeksThe First Programming Languages: Crash Course Computer Science #11Longest Common Subsequence (Dynamic Programming)Count Square Submatrices with All Ones - LeetCode May 21 ChallengeMaximum sum sub-arrayFind the missing number in duplicate arrayLargest Square Submatrix of all 1's | Dynamic ProgrammingCoding Interview Question | Max size square submatrix with all 1s | Dynamic ProgrammingPrint Matrix in spiral form ( 2-D array)Maximum Sum Rectangular Submatrix in Matrix dynamic programming/2D kadaneDimension of the null space or nullity | Vectors and spaces | Linear Algebra | Khan AcademyLongest Duplicate Substring | TRIE | Rolling Hash | Binary Search | Leetcode #1044Largest Square of 1's in A Matrix (Dynamic Programming)Trick for spiral matrix traversalLargest Node on the Right for Each Node in a Linked ListGOOGLE CODING INTERVIEW QUESTION - KTH LARGEST ELEMENT IN AN ARRAY (LeetCode)