| CSCI A201/A597Problem Set Nine Second Summer 2000 |
| 1. |
Write a method that computes the scalar product of two mathematical vectors (represented as arrays). The scalar product is:static double scalarProduct(double[] a, double[] b) a0b0 + a1b1 + ... + an-1bn-1 |
| 2. |
Write a method that computes the alternating sum of all elements
in an array. For example, if alternatingSum is called with an array containing
1 4 9 16 9 7 4 9 11Then it computes 1 - 4 + 9 - 16 + 9 - 7 + 4 - 9 + 11which is, of course, -2.
|
| 3. |
Write a method reverse that reverses the sequence of elements
in an array. For example, if reverse is called with an array containing
1 4 9 16 9 7 4 9 11then the array is changed to 11 9 4 7 9 16 9 4 1 |
| 4. |
Write a method
that appends one array after another. For example, ifpublic static int[] append(int[] a, int[] b) a is
1 4 9 16and b is
9 7 4 9 11then append returns the array
1 4 9 16 9 7 4 9 11 |
| 5. |
Write a predicate method
that checks whether two arrays have the same elements in the same order.public static boolean equals(int[] a, int[] b) |
| 6. |
Write a predicate method
that checks whether two arrays have the same elements in some order, ignoring multiplicities. For example, the two arrayspublic static boolean sameSet(int[] a, int[] b) 1 4 9 16 9 7 4 9 11and 11 11 7 9 16 4 1would be considered to have the same set. You will probably need one or more helper methods. |
| 7. |
Write a predicate method
that checks whether two arrays have the same elements in some order, with the same multiplicities. For example,public static boolean sameElements(int[] a, int[] b) 1 4 9 16 9 7 4 9 11and 11 1 4 9 16 9 7 4 9would be considered to have the same elements, but 1 4 9 16 9 7 4 9 11and 11 11 7 9 16 4 1would not. You will probably need one or more helper methods. |