Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Any help will be useful, thank you! For problem below assume the following defin

ID: 3791034 • Letter: A

Question

Any help will be useful, thank you!

For problem below assume the following definitions. Let A [] be an array of integers. Let A| [] = n be the size of the array equals to n, for n greaterthanorequalto 0, where A[0], A[1], A [2], ..... A[n - 1] are the first, second, third, and last element of array, respectively. Let now divide array A[], of size n greaterthanorequalto 1, in two parts, H (head) and T (tail, where His the first element of the array and T is the array with remaining elements. For example, if A [] = [3, 4, 1, 6, 8], then |A []| = 5, A[1] = 4, A[2] = 1, A [3] = 6, A[4] = 8, H = 3, and T = [4, 1, 6, 8] In the case that |A[]| = 1, then H = A[0] and T is empty. Find the largest value in an array of integers. We can find the largest value in an array of size n recursively as follows: largest (A[]) = {H, if |A[]| = 1 Max (H, largest(T)), if |AV| > 1} Complete the iterative method below to find the largest value of a given array A []. public static int largest Iterative (int [] A) {largest = A[O]; for (I = ________; i

Explanation / Answer

Ques 1

public static int largestIterative(int[] A)[

{

largest = A[0];

for(int i=0;i<A.length;i++)

if(largest<A[i])

largest = A[i];

return largest;

}

Ques 2

public static int largestRecursive(int[] A)

{

                If(A.length==0)

return A[0];

else{

                int[] T = new int[A.length-1];

                for(int i=1;i<A.length;i++)

                                T[i-1] = A[i];

return Math.max(largestRecursive(T),A[i])

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote