0% found this document useful (0 votes)
3 views1 page

Java Array Practice Set for CSE AI

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java Array Practice Set for CSE AI

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Amrita School of Engineering - Chennai Campus

19AIE105 – Object Oriented Paradigm


JAVA Practise Set - Arrays
CSE AI Date: 04 Dec 2020
Sem: 1

1. Write a program to find the maximum and minimum element from an array
of n elements.
2. Write a Java program to find the common elements between two arrays
3. Write a Java program to add two matrices of the same size.
4. Write a Java program to test if an array contains a specific value.
5. Write a java program to do matrix multiplication.
6. Write a Java program to remove the duplicate elements of a given array
and return the new length of the array.
Sample array: [20, 20, 30, 40, 50, 50, 50]
After removing the duplicate elements, the program should return 4 as the
new length of the array.
7. Write a Java program to separate even and odd numbers of a given array
of integers. Put all even numbers first, and then odd numbers.
8. Java Program to Find the Number of Non-Repeated Elements in an Array.
9. Given an array containing 0s and 1s, write a Java Program to Segregate 0s
on Left Side & 1s on Right Side of the Array
[Link] Program to Print All the Repeated Numbers with Frequency in an
Array.
[Link] Program to Display Transpose Matrix

------------------------------------------------------

Common questions

Powered by AI

Two matrices can be added in Java by iterating through each corresponding element of the matrices and summing them. It is necessary for the matrices to be of the same size because matrix addition is defined element-wise; each element in one matrix must directly correspond to an element in the other matrix to produce a meaningful result.

Removing duplicates from an array is important to ensure elements are unique, which can optimize performance in certain algorithms and storage. In the sample array [20, 20, 30, 40, 50, 50, 50], the new length after removing duplicates is 4. This means only unique values remain, enhancing clarity and preventing redundancy.

Segregating 0s and 1s in an array is important in optimizing storage and processing binary arrays, which can simplify algorithms that rely on binary data. In Java, this can be achieved using two pointers placed at the beginning and end of the array, swapping elements to place all 0s on one side and all 1s on the other. This improves data efficiency and enhances algorithm performance.

Matrix multiplication is necessary in various computational scenarios such as graphics transformations, solving linear systems, and in algorithms for neural networks. In Java, it is implemented by computing the dot product of the rows of the first matrix with the columns of the second matrix, ensuring that the number of columns in the first matrix equals the number of rows in the second matrix. This operation has a complexity of O(n^3)

The algorithmic approach to find the maximum and minimum elements from an array in Java involves iterating through the array once while keeping track of the current maximum and minimum values. This method is efficient, with a time complexity of O(n), because it only requires a single pass through the array which minimizes the number of comparisons and operations.

Java can find the number of non-repeated elements in an array using a HashMap to track occurrences of each element, and then counting how many have a frequency of one. This functionality is useful for analyzing unique data distributions and filtering out noise in datasets, enhancing clarity and insight into data structures and behaviors.

The significance of segregating even and odd numbers lies in organizing data for specific computational purposes, like optimizing search or simplifying other operations. This can be achieved in Java by iterating through the array, using two pointers: one for even and another for odd numbers, swapping elements to place all even numbers first and then the odd ones. This method improves data organization and efficiency for subsequent operations.

The main challenge in finding the transpose of a matrix is efficiently switching rows with columns while maintaining data integrity. Java addresses this by creating a new matrix where the elements at row index i and column j in the original are placed at row j and column i in the transpose. This method efficiently reorganizes data structure and keeps computational costs manageable.

The frequency of repeated numbers in an array can be determined in Java using a HashMap. By iterating through the array and counting instances of each element with the HashMap, the frequency of each number can be calculated and stored effectively. This provides a clear frequency distribution of the elements, allowing for quick access and updates.

Testing an array for a specific value is crucial for searching and data verification purposes. In Java, this can be performed using a simple loop through the array to check if any element matches the target value. This operation aids quick verification and retrieval of data, ensuring data integrity and informed decision-making.

You might also like