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;     }           }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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<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;
    }
    
    

}

Maximum Subarray
findMaxSubarry (arr, low, high)
if high-low
else
return (low high, arr [low])
mid= mid point of arr
(1-low, 1-high, 1-sum)
(r-low, r-high, r-sum)
(c-low, c-high, c-sum)
if 1-sum 2 r-sum and
else
findMaxCrossing (arr, low, mid, high)
1-sum = MIN
0
sum =
for i mid downto low
sum = sum arr[i]
if sum > 1-sum
return (1-low, l-high, 1-sum)
else if r-sum ≥l-sum and r-sum ≥c-sum
return (r-low, r-high, r-sum)
return (c-low, c-high, c-sum)
MIN
1-sum = sum
max-left
r-sum =
sum =
0
for j=mid+1 to high
=
i
low, mid)
mid+1, high)
findMaxCrossing (arr, low, mid, high)
1-sum 2 c-sum
sum = sum + arr[j]
if sum > r-sum
=
=
findMaxSubarray(arr,
findMaxSubarray(arr,
=
r-sum sum
max-right = j
return (max-left, max-right, 1-sum+r-sum);
Transcribed Image Text:Maximum Subarray findMaxSubarry (arr, low, high) if high-low else return (low high, arr [low]) mid= mid point of arr (1-low, 1-high, 1-sum) (r-low, r-high, r-sum) (c-low, c-high, c-sum) if 1-sum 2 r-sum and else findMaxCrossing (arr, low, mid, high) 1-sum = MIN 0 sum = for i mid downto low sum = sum arr[i] if sum > 1-sum return (1-low, l-high, 1-sum) else if r-sum ≥l-sum and r-sum ≥c-sum return (r-low, r-high, r-sum) return (c-low, c-high, c-sum) MIN 1-sum = sum max-left r-sum = sum = 0 for j=mid+1 to high = i low, mid) mid+1, high) findMaxCrossing (arr, low, mid, high) 1-sum 2 c-sum sum = sum + arr[j] if sum > r-sum = = findMaxSubarray(arr, findMaxSubarray(arr, = r-sum sum max-right = j return (max-left, max-right, 1-sum+r-sum);
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education