Given a series Q of N integers (positive or negative), the max subarray of Q is the largest contiguous subarray such that the sum of its element is maximum.
For example, given Q
The max subsequence is
6
-1
8
Remark : if the max subarray is not unique, the first one should be returned.
There are many solutions to this problem. One is Kadane's algorihm which solves it in O(N) but cannot be parallelized. We will consider a solution proposed by Perumalla et al.
This solution relies on 2 applications of the SCAN/PREFIX algorithm. The first one is sum-prefix and uses the sum operation on the array. The second is max-prefix and uses the max function. To implement it, simply start from the sum-prefix version and replace sum with max()
and the initial 0 values with the neutral value for max.
It also uses a SUFFIX operation which works in reverse order on the array.
Max subarray :
Input : Q array of N integers
Output : Max subsequence
This example comes from the article in references. It is important to understand each step and verify the computation.
The algorithm should be implemented in a single file yourSurname.c (family name) with the following constraints.
The input file is assumed to be well written, i.e. no errors, correct numbers...It will contain n =2ˆm elements.
The following zip file contains a python script for testing your solution. Place your file yourSurname.c in the src directory and execute the following command :
~/>python3 evaluate.py
yourName;True;True;False;Error
The first column is the compilation result (Trues). The second column is the first dataset, it's True so everything is fine. The second dataset have given an incorrect result (False) and the last one crashed or did not produce results after a 5s timeout.
The project should be submitted as a GitHub repository on https://classroom.github.com/a/uK9aYVM8 as 2 files before the 15th of January, 6.00pm with the final version in the master branch.
gcc -o nom -Wall -std=c99 nom.c -lm -fopenmp
The following points are evaluated
The evaluation of mostly done automatically so if the output format is incorrect, the program will be assumed to be incorrect !