Question: This script will call a C++, Java, or Rust program that takes a command-line argument inputFile.json, and verify that each sample is a sorted array.
This script will call a C++, Java, or Rust program that takes a command-line argument inputFile.json, and verify that each sample is a sorted array. If a sample array is not sorted, there must be some position i such that the ith element is equal to or larger than the i+1st element. We call this a consecutive inversion. For example, if A = [2, 0, 3, 2, 5] there is a consecutive inversion at location i = 2 because A[2] = 3 2 = A[3]. For example, the samples:
Sample1=[1641818748,1952682320,195384256,1702150187], and Sample2 = [683761375, 406924096, 362070867, 592214369]
are defined by the following input file SampleExample.json: {
"Sample1": [-319106570,811700988,1350081101,1602979228], "Sample2": [-319106570,811700988,797039,-1680733532], "metadata": { "arraySize":4,
"numSamples":2 }
}
Sample2 has consecutive inversions at index 1 and 2, and running
./sortedverification.sh SampleExample.json
outputs a JSON file whose contents are printed to stdout:
{"Sample2":{"ConsecutiveInversions":{"1":[811700988,797039],"2": [797039,-1680733532]},"sample":[-319106570,811700988,797039,-1680733532]}, "metadata":{"arraySize":4,"file":"SampleExample.json","numSamples":2, "samplesWithInversions":1}} The above text is printed on a single line to stdout (use output redirection to save to a file). To make it readable, use https://jsonformatter.curiousconcept.com/ to obtain a human readable version of this string (i.e. whitespace is added for clarity):
{ "Sample2":{ "ConsecutiveInversions":{ "1":[ 811700988,
797039 ],
"2":[ 797039,
-1680733532 ]
}, "sample":[
-319106570,
6
811700988, 797039, -1680733532
] },
"metadata":{ "arraySize":4, "file":"SampleExample.json", "numSamples":2, "samplesWithInversions":1 } }
You can also view this output in the file SV-SampleExample.json. Sample1 has no inversions so its data is not printed to the JSON output above. Notice that if the consecutive inversions of a sample are added to the JSON object, the sample data (the array) is also added to the JSON object.
Use c++ please
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
