(Largest block) Given a square matrix with the elements 0 or l, write a
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.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Modern Database Management
Problem Solving with C++ (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- Exercise 1: (Design of algorithm to find greatest common divisor) In mathematics, the greatest common divisor (gcd) of two or more integers is the largest positive integer that divides each of the integers. For example, the gcd of 8 and 12 is 4. Why? Divisors of 8 are 1, 2, 4, 8. Divisors of 12 are 1, 2, 4, 6, 12 Thus, the common divisors of 8 and 12 are 1, 2, 4. Out of these common divisors, the greatest one is 4. Therefore, the greatest common divisor (gcd) of 8 and 12 is 4. Write a programming code for a function FindGCD(m,n) that find the greatest common divisor. You can use any language of Java/C++/Python/Octave. Find GCD Algorithm: Step 1 Make an array to store common divisors of two integers m, n. Step 2 Check all the integers from 1 to minimun(m,n) whether they divide both m, n. If yes, add it to the array. Step 3 Return the maximum number in the array.arrow_forward(Average the major diagonal in a matrix) Write a method that averages all the numbers in the major diagonal in an n * n matrix of double values using the following header: public static double averageMajorDiagonal(double[][] m) Write a test program that reads a 4-by-4 matrix and displays the average of all its elements on the major diagonal. Here is a sample run: 1 2 3 4.0 5 6.5 7 8 9 10 11 12 13 14 15 16 Average of the elements in the major diagonal is 8.625arrow_forward(Sum elements row by row) write a method that returns the sum of all the elements in a specified row in a matrix using the following header: public static double sumRow(double [][] m, int rowIndex) Write a test program that reads a 3-by-4 matrix and displays the sum of each row here is a sample run.arrow_forward
- Write a menu driven C++ program that should perform following operation on matrices using 2D arrays. (Use OOP) The program will first take inputs for both matrices from the user then perform following operations on them: 1.CheckTranspose() This method will ask from user which matrix you want to take transpose and then display its transpose. 2.CheckSymmetric() This method will check symmetric matrix 3.CheckIdentity() This method will check if the matrix is identity 4. Multiplication() This method will multiply two matrices but first check number of rows and columns of corresponding matrices and display "Not possible" in case of inequality in rows and columns. Dont use pointers please use counters only.. Thank you very much.arrow_forward(Algebra: multiply two matrices) Write a method to multiply two matrices. The header of the method is: public static double[][] multiplyMatrix(double[][] a, double[][] b) To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element cij is ai1 × b1j + ai2 × b2j + g + ain × bnj. For example, for two 3 × 3 matrices a and b, c is a11 a12 a13 a21 a22 a23 a31 a32 a33 where cij = ai1 * b1j + ai2 * b2j + ai3 * b3j . Write a test program that prompts the user to enter two 3 * 3 matrices and displays their product.arrow_forward(Algebra: multiply two matrices) Write a method to multiply two matrices. The header of the method is: public static double[][] multiplyMatrix(double[][] a, double[][] b) To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element cij is ai1 × b1j + ai2 × b2j + g + ain × bnj. For example, for two 3 × 3 matrices a and b, c is where cij = ai1 * b1j + ai2 * b2j + ai3 * b3j . Write a test program that prompts the user to enter two 3 * 3 matrices and displays their product. Here is a sample run: Ps: pls do the same header and the output is the same on the picture thanksarrow_forward
- (Needs to write a java program. The imput file that the code will be tested on will be really large, but a code that can work on the provided sample in the picture should work just fine) An image is an array, or a matrix, of pixels (picture elements) arranged in columns and rows. RGB is one of the models used in color pixels. In a color image, each RGB pixel is an integer number which contains the mixture of red, green and blue colors. In this assignment, you will be provided with an image data file, image.dat. The first line in data file contains the height (rows) and width (columns) of the image. The following lines gives the red, green and blue color integer values for each pixel. The following sample.dat is given as an example: (The given example can be seen on the picture down) According to this input file, the image has 4 rows and 2 columns. The pixel at [0][0] has red value 117, green value 117 and blue value 245. Write a Java program that reads from the given input file and…arrow_forwardWrite a menu driven C++ program that should perform following operation on matrices using 2D arrays. (Use OOP Please to write minimum code) The program will first take inputs for both matrices from the user then perform following operations : Subtract() This method will subtract two matrices. Multiply() This method will multiply two matrices but first check number of rows and columns of corresponding matrices and display "Not possible" in case of inequality in rows and columns. AddScalar() This method will add scalar to a matrix by asking user in which matrix to add. CheckTranspose() This method will ask from user which matrix you want to take transpose and then display its transpose. CheckSymmetric() This method will check symmetric matrix CheckIdentity() This method will check if the matrix is identity CheckUpperTriangular() This method will check upper triangular matrix Dont use pointers please use counters only.. Thank you very much. use oop pleasearrow_forward(Sort three numbers) Write the following function to display three numbers in increasing order: def displaySortedNumbers(num1, num2, num3): Write a test program that prompts the user to enter three numbers and invokes the function to display them in increasing order. Here are some sample runs:arrow_forward
- (Random sentences and story writer) Write an app that uses random-number generation to create sentences. Use four arrays of strings, called article, noun, verb andprepostion. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article, noun.As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the sentence is output, it should start witha capital letter and end with a period. The program should generate 10 sentences and output them to a text box. The arrays should be filled as follows:The article array should contain the articles "the", "a", "one", "some" and "any";The noun array should contain the nouns "boy", "girl", "dog", "town", "car";The verb array should contain the past tense verbs "drove", "jumped", "ran", "walked" and "skipped";The preposition array should contain the preposotions "to", "from", "over", "under" and "on";arrow_forward(Evaluation of Trainees) Use a two-dimensional array to solve the following problem: A company has four trainees (1 to 4) who take five different programs (1 to 5). Once a week, the trainer creates evaluation results for each program taken. Each result contains the following: a. The trainee number b. The program number c. The score of that program taken that week (0 to 10 scores) Thus, the trainer creates 5 results per week for each trainee. Assume that the information from all the results for last month is available. Write an application that will read all this information for last month’s results and summarize the total scores by the trainee and by the program. All totals should be stored in the two-dimensional array. After processing all the information for last month, display the results in tabular format, with each column representing a trainee an each row representing a particular program. Average each row to get the average scores of each program for last month.…arrow_forward(with Java please)arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning