Question: Please help me with this Java problem . Take your time! 1.The sum_getImple Method /** * Get the total of the values in an integer

Please help me with this Java problem . Take your time!

Please help me with this Java problem . Take your time! 1.The

sum_getImple Method /** * Get the total of the values in an

1.The sum_getImple Method

/** * Get the total of the values in an integer list * @param nums The list of integers * @return The sum of the values */ public int sum_getImple(java.util.List nums) { int total = 0; for(int i = 0; i

2.The sum_iteratorImple Method

/** * Get the total of the values in an integer list * @param nums The list of integers * @return The sum of the values */ public int sum_iteratorImple(java.util.List nums) { int total = 0; java.util.Iterator it = nums.iterator(); while(it.hasNext()) { total += it.next(); } return total; }

3.The removeEvens_getImple Method

/** * Remove the even values from a list of integers. * The method modifies the parameter list. * @param nums The list of integers */ public void removeEvens_getImple(java.util.List nums) { for(int i = 0; i

4.The removeEvens_iteratorImple Method

/** * Remove the even values from a list of integers. * The method modifies the parameter list. * @param nums The list of integers */ public void removeEvens_iteratorImple(java.util.List nums) { java.util.Iterator it = nums.iterator(); while(it.hasNext()) { int value = it.next(); if(value % 2 == 0) { it.remove(); } } }

5.The double_getImple Method

/** * Double the values in a list of integers. * This method modifies the parameter list. * @param nums The list of integers */ public void double_getImple(java.util.List nums) { for(int i = 0; i

6.The double_iteratorImple Method

/** * Double the values in a list of integers. * This method modifies the parameter list. * @param nums The list of integers */ public void double_iteratorImple(java.util.List nums) { java.util.ListIterator it = nums.listIterator(); while(it.hasNext()) { int value = it.next(); it.set(2 * value); } }

The format of the answer should look like something like included explaining in a txt file.

When nums is an ArrayList, the sum_getImple method is O( When nums is an LinkedList, the sum_getImple method is O( When nums is an ArrayList, the sum_iteratorImple method is O( When nums is an LinkedList, the sum_iteratorImple method is O(

....

In this assignment, you will consider several algorithms which use the methods of java.util.List, giving the algorithmic efficiency and a brief description of the reason. The algorithms are encoded in standard Java methods which have a java.util.List parameter. The analysis shall consider what the Big-O for the method will be when passed an instance of java.util.ArrayList and when passed an instance of java.util.LinkedList An Example Let's look at an example of what you will be doing for this assignment. Consider the following simple method: * Add tuo elements of a list of Integers eparam nums The list of integers @param index! The first index value @param index2 The secdond index value t @return The sum of the two elements @throvs Illega 1 Argument Exception when index values t are out of range public int addTwo (java.util.List nums, int index1, int index2) if ( index1 = nums . size ( ) !! index2 = nums . size()) { String msg = "Index value out of range"; throw new IllegalirgumentException (msg) return nums.get (index + nums.get (index2) Like the problems which make up this assignment, this method has a java.util. List parameter. We need to determine the Big-O for this method if the parameter nums is a java.util.ArrayList and if nums is a java.util LinkedList. We also must give the reason The Sample Solution When nums is an ArrayList, the addTwo method is O(k), constant time. This is because the get method of ArrayList takes constant time. The size of the list does not have an effect on the time it takes to access a given element of the list, accessing any element in an array takes the same amount of time. When nums is a LinkedList, the addTwo method is O(N), linear time. This is because the get method of LinkedList takes linear time. The larger the list, the longer time it make take to access a given element, since finding the n-th element requires handling n-1 linked elements

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 Databases Questions!