For this problem, you will implement divide and conquer algorithms: the maximum subarray. I have provided the pseudo code for algorithms below. You will need to handle cases of all sizes, not just powers of 2. Maximum Subarray using Divide and Conquer Create a class called MaxSubFinder in the divideandconquer package. This class will implement the maximum subarray problem on an array using the pseudocode described above. Implement the following methods with the exact signatures below. You will need to create private helper methods to do most of the work. You can assume that the array and list are not empty. public static Triple getMaxSubarray(int[] arr) This method returns a triple that represents the maximum subarray. The first element of the triple is the index in arr where the maximum subarray starts, the middle element of the triple is where the index in the arr where maximum subarray ends, and the last element of the triple is the maximum subarray sum. package divideandconquer; public class Triple { First first; Middle middle; Last last; public Triple(First first, Middle middle, Last last) { this.first= first; this.middle = middle; this.last = last; } public First getFirst() { return first; } public void setFirst(First first) { this.first = first; } public Middle getMiddle() { return middle; } public void setMiddle(Middle middle) { this.middle = middle; } public Last getLast() { return last; } public void setLast(Last last) { this.last = last; } }
For this problem, you will implement divide and conquer
2.
Maximum Subarray using Divide and Conquer
Create a class called MaxSubFinder in the divideandconquer package. This class will
implement the maximum subarray problem on an array using the
pseudocode described above. Implement the following methods with the exact signatures
below. You will need to create private helper methods to do most of the work. You can
assume that the array and list are not empty.
public static Triple<Integer,Integer,Integer> getMaxSubarray(int[] arr)
This method returns a triple that represents the maximum subarray. The first element of
the triple is the index in arr where the maximum subarray starts, the middle element of the
triple is where the index in the arr where maximum subarray ends, and the last element of
the triple is the maximum subarray sum.
package divideandconquer;
public class Triple<First,Middle,Last> {
First first;
Middle middle;
Last last;
public Triple(First first, Middle middle, Last last) {
this.first= first;
this.middle = middle;
this.last = last;
}
public First getFirst() {
return first;
}
public void setFirst(First first) {
this.first = first;
}
public Middle getMiddle() {
return middle;
}
public void setMiddle(Middle middle) {
this.middle = middle;
}
public Last getLast() {
return last;
}
public void setLast(Last last) {
this.last = last;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images