Part 1

Write a method int[] mixReverse(int[] arr1, int[] arr2) that

  • Checks that the two parameters have the same length. If they do not, the method prints an error message and returns a copy of array arr1.
  • Returns a new array of length twice that of arr1. This array consists of the array arr1 interleaved with the reverse of array arr2. Specifically, the new array contains in order arr1[0], arr2[arr2.length-1], arr1[1], arr2[arr2.length-2], ... arr1[arr1.length-1], arr2[0]

Write a main() method that

  • Reads an integer N followed by 2N integers.
  • Assigns the first N of the 2N to an array x.
  • Assigns the remaining N to an array y.
  • Calls mixReverse and prints the values returned in order.

Part 2

Copy the insSort() method from the notes or book See image.

Write a main() method that

  • Creates an array a1 of length 10 with a[i]=i and prints the array.
  • Defines an array a2 of length 20, executes a2=mixReverse(a1,a1), and prints the array.
  • Defines an array a3 of length 40, executes a3=mixReverse(a2,a2), and prints the array.
  • Copies a3 to a new array a4.
  • Sorts a3 using insSort() and prints the result, which should be 0,0,0,0,1,1,1,1,2,....
  • Sorts a4 using sort() from the Java library and prints the result, which should again be 0,0,0,0,1,1,1,1,2,....

Part 3

Write a method double mean(double[]x) that accepts an array of doubles and return the mean (often called the average).

Write a main() method that

  • Defines an array of 101 doubles and initializes it to 101 random numbers using Math.random(). Each of these numbers will be greater than or equal to 0 and less than 1.
  • Uses mean() to find the mean.
  • Sorts the array using java.util.Arrays.sort() and records the median (the middle value, which is component 50 since the array is now sorted).
  • Prints the mean, the median, and states which is larger.
  • Does all the above in a loop 1000 times and when the loop ends states how many times the mean was larger, how many times the median was larger, and how many times they were equal.

Part 4 Matrix Multiplication

Write a method

public static void matrixMult(int n, double[][]A, double[][]B, double[][]C)

Matrix multiplication is not commutative. That is, if A and B are each n×n square matrices, then it is not always true that AB=BA.

Write a program that does the following.

  • Inputs an integer n and checks that it is positive.
  • Creates two n×n double matrices A and B.
  • Inputs values for A and B.
  • Computes and prints both AB and BA.
  • Computes and prints AB-BA.
  • Prints whether the matrices were commutative or not.
  • Inputs an integer p and checks that it is positive.
  • Prints Aj-Bj and (A-B)j, for j=1,2,..p.

Whenever the user is to input values, a prompt must be printed. That prompt can specify the number of values the user must supply

Part 5

Given a 3D double matrix M of size n×n×n, then each M[i] is an n×n 2D matrix.

Consider a new operation ***defined on 3D n×n×n matrices as follows. Given two such 3D matrices A and B, (A***B)[i] is the ordinary 2D matrix product (A[i])(B[i]).

Write a program that does the following.

  • Inputs an integer n and checks that it is positive.
  • Creates an n×n×n 3D double matrix M.
  • Inputs values for M.
  • Inputs an integer p and checks that it is positive.
  • Prints M, M***M, (M***M)*M, ((M***M)*M)*M, ... up to p *** operations.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.