|
First Summer 2006 |
Also, please make sure you
with the Computer Science Department's Statement on Academic Integrity before turning in your assignment.
Write a method calledscalarProductthat computes the scalar product of two mathematical vectors (represented as lists). The scalar product is:a0b0 + a1b1 + ... + an-1bn-1
Write a method that computes the alternating sum of all elements in a list of numbers. For example, ifalternatingSumis called with a list containing1 4 9 16 9 7 4 9 11Then it computes1 - 4 + 9 - 16 + 9 - 7 + 4 - 9 + 11which is, of course,-2.
Write a methodreversethat reverses the sequence of elements in an array. For example, ifreverseis called with an array (or list) containing1 4 9 16 9 7 4 9 11then the array is changed to11 9 4 7 9 16 9 4 1
Write a predicate method equals that checks whether two arrays have the same elements in the same order.
Write a predicate methodsameSetthat checks whether two arrays have the same elements in some order, ignoring multiplicities. For example, the two arrays1 4 9 16 9 7 4 9 11and11 11 7 9 16 4 1would be considered to have the same set. You may or may not need one or more helper methods.
Write a predicate methodsameElementsthat checks whether two arrays have the same elements in some order, with the same multiplicities. For example,1 4 9 16 9 7 4 9 11and11 1 4 9 16 9 7 4 9would be considered to have the same elements, but1 4 9 16 9 7 4 9 11and11 11 7 9 16 4 1would not.You may or may not need one (or more) helper method(s).