Question: I need an java expert in algorithm Task 0 ( Number of groups ) Change the method public static int groupMembers ( ) so that

I need an java expert in algorithm
Task 0(Number of groups)
Change the method public static int groupMembers() so that it returns the number of people who are in
the group. If you work alone, it should return 1, for example, and if there are four of you in the group, it
should return 4.
Exercise 1(Find the largest number)
In the lectures, we have looked at various techniques for finding the position of the largest value in a
table. In this assignment, a different technique will be used. However, since this technique modifies the
table, it is the value itself that should be returned (and not the position). Create the method public static
int max(int[ a). It should find and return the largest value in table a. You should use the following
algorithm:
Compare the first two items in the table. If the first element is larger, swap the two values.
Then compare the next two elements in the table (element 2 and 3, then index 1 and 2). If the
first of them is larger, swap the two values.
Continue with the next two items, then the next two, until you've gone through the entire table.
When the method is finished, the table's largest value will be at the back, and you can return this. The
method should throw a NoSuchElementException with the appropriate text on an empty table, as an
empty table does not have a largest value.
In such a maximum method, we are primarily concerned with the number of comparisons, but we
are also interested in the number of replacements. Let n represent the number of values in the table,
and assume that the table contains a random permutation of the numbers from 1 to n .
(a) How many comparisons will there be, as a function of n?
(b) When will there be fewest substitutions?
(c) When will there be the most exchanges?
(d) How many replacements will there be on average?
To help us answer the last three questions, create a method that uses the same algorithm as the
max method, but instead returns the number of swaps made, and returns this. Let it be called public
static int swaps(int[] a). Make random permutations of the numbers from 1 to n , and use this method to
get an indication of what the answer is.
There is a formula for what the average number of replacements is, and you should
find out this formula.
Can you, on the basis of the information you have found out, say about this max-
is the method better or worse than the max methods we have looked at previously?
I need an java expert in algorithm Task 0 (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!