Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write new code: 1. Given a square matrix with the elements 0 or 1 , write a program to find a maximum square submatrix

Please write new code:

image text in transcribedimage text in transcribed

1. Given a square matrix with the elements 0 or 1 , write a program to find a maximum square submatrix whose elements are all 1s. Your program should prompt the user to enter the number of rows in the matrix. The program then displays the location of the first element in the maximum square submatrix and the number of rows in the submatrix. Your program should implement and use the following method to find the maximum square submatrix: public static int[] findLargestBlock(int[][] m) The return value is an array that consists of three values. The first two values are the row and column indices for the first element in the submatrix, and the third value is the number of the rows in the submatrix. Sample Run: Enter the number of rows in the square matrix: 5 Enter the matrix row by row: 1111101000111110011111111 The maximum square submatrix is at (2,2) with size 3 Given a binary matrix, find out the maximum size square sub-matrix with all 1s. Algorithm: Let the given binary matrix be M[R][C]. The idea of the algorithm is to construct an auxiliary size matrix S[][] in which each entry S[i][j] represents size of the square sub-matrix with all 1s including M[i][j] where M[i][j] is the rightmost and bottommost entry in sub-matrix. 1) Construct a sum matrix S[R][C] for the given M[R][C]. a) Copy first row and first columns as it is from M[][] to S[][] b) For other entries, use following expressions to construct S[][] If M[i][j] is 1 then S[i][j]=min(S[i][j1],S[i1][j],S[i1][j1])+1 Else /*If M[i][j] is 0/ S[i][j]=0 2) Find the maximum entry in S[R][C] 3) Using the value and coordinates of maximum entry in S[i], construct the return array For the given M[R][C] in above example, constructed S[R][C] would be: 010110111120101220011230100010 The value of maximum entry in above matrix is 3 and coordinates of the entry are (4, 3). Using the maximum value and its coordinates, we can find out the return array: {2,1,3}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

3. Provide advice on how to help a plateaued employee.

Answered: 1 week ago