Found 73 Articles for Campus Interview

Java Program To Determine If a Given Matrix is a Sparse Matrix

AmitDiwan
Updated on 29-Mar-2022 10:17:26

229 Views

In this article, we will understand how to determine if a given Matrix is a sparse matrix. A matrix is said to be sparse matrix if most of the elements of that matrix are 0. It implies that it contains very less non-zero elements.Below is a demonstration of the same −Suppose our input is −Input matrix: 4 0 6 0 0 9 6 0 0The desired output would be −Yes, the matrix is a sparse matrixAlgorithmStep 1 - START Step 2 - Declare an integer matrix namely input_matrix Step 3 - Define the values. Step 4 - Iterate over each ... Read More

Java Program to display upper triangular matrix

AmitDiwan
Updated on 29-Mar-2022 10:12:27

660 Views

In this article, we will understand how to display an upper triangular matrix. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix. An upper triangular matrix is a triangular matrix with all elements below the main diagonal are 0.Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 2 1 4 1 2 3 3 6 2The desired output would be −The upper triangular matrix is: 2 1 4 0 2 3 0 0 2AlgorithmStep 1 ... Read More

Java Program to Recursively Linearly Search an Element in an Array

AmitDiwan
Updated on 29-Mar-2022 10:05:33

2K+ Views

In this article, we will understand how to recursively linearly search an element in an array. Linear search is a very simple search algorithm wherein a sequential search is done for all items one by one.Below is a demonstration of the same −Suppose our input is −Input array: 14 20 35 47 50 65 72 81 90 99 Key element: 72The desired output would be −The element 72 is present at position: 6AlgorithmStep 1 - START Step 2 - Declare a string array namely input_array, two integer namely key_element and index Step 3 - Define the values. Step 4 ... Read More

Java Program To Find the Trace and Normal of a given Matrix

AmitDiwan
Updated on 29-Mar-2022 09:53:05

287 Views

In this article, we will understand how to find the trace and normal of a given matrix. The normal of a matrix is the square root of the sum of squares of all the elements of a matrix. The trace of a matrix is the sum of all the elements present in the principal diagonal (upper left to lower right).Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 2 3 4 5 2 3 4 6 9The desired output would be −Trace value: 13.0 Normal value: 14.142135623730951AlgorithmStep 1 - START Step 2 - ... Read More

Java Program to Multiply to Matrix Using Multi-Dimensional Arrays

AmitDiwan
Updated on 29-Mar-2022 09:45:12

731 Views

In this article, we will understand how to multiply to matrix using multi-dimensional arrays. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix.Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −First matrix: 2 3 4 5 2 3 4 6 9 Second matrix: 1 5 3 5 6 3 8 ... Read More

Java Program to Add Two Matrix Using Multi-Dimensional Arrays

AmitDiwan
Updated on 29-Mar-2022 09:38:26

787 Views

In this article, we will understand how to add two matrix using multi-dimensional arrays. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix. Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −First matrix: 2 3 4 5 2 3 4 6 9 Second matrix: 1 5 3 5 6 3 ... Read More

Java Program to Interchange the Diagonals

AmitDiwan
Updated on 29-Mar-2022 09:32:22

143 Views

In this article, we will understand how to interchange the diagonals. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix.Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 4 5 6 1 2 3 7 8 9The desired output would be −The matrix after interchanging the elements: ... Read More

Java Program to Interchange Elements of First and Last in a Matrix Across Columns

AmitDiwan
Updated on 29-Mar-2022 09:23:17

467 Views

In this article, we will understand how to interchange elements of first and last in a matrix across columns. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix.Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 4 5 6 7 1 7 3 4 11 12 13 ... Read More

Java Program to Interchange Elements of First and Last in a Matrix Across Rows

AmitDiwan
Updated on 29-Mar-2022 09:17:39

133 Views

In this article, we will understand how to interchange elements of first and last in a matrix across rows. The matrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m × n matrix.Individual entries in the matrix are called element and can be represented by a[i][j] which suggests that the element a is present in the ith row and jth column.Below is a demonstration of the same −Suppose our input is −The matrix is defined as: 4 5 6 7 1 7 3 4 11 12 13 ... Read More

Java Program to Compute the Sum of Diagonals of a Matrix

AmitDiwan
Updated on 18-Jun-2024 17:51:56

8K+ Views

In this article, we will understand how to compute the sum of diagonals of a matrix. The matrix has a row and column arrangement of its elements. The principal diagonal is a diagonal in a square matrix that goes from the upper left corner to the lower right corner.The secondary diagonal is a diagonal of a square matrix that goes from the lower left corner to the upper right corner.Below is a demonstration of the same −Suppose our input is −The input matrix: 4 5 6 7 1 7 3 4 11 12 13 14 23 24 25 50The desired ... Read More

Advertisements