Question: Main thread randomly generates an array of double values with a given size ( say , N = 1 0 0 0 ) , and

Main thread randomly generates an array of double values with a given size (say, N=1000), and divides it into two smaller arrays of equal size. It then passes each sub-array to sorting_avg thread (creates two copies of the same thread), and waits until these two sub-arrays are sorted and the average of the values in each array are computed. It then calls merging_avg thread by passing the already sorted two sub-arrays, and the averages of the first and second sub-arrays as parameters.
Sorting_avg thread sorts the given sub-array using insertion sort or selection sort (one is enough and you need to implement either one), and computes the average of the values in the given array. So this thread returns sorted sub-array and its average.
Merging_avg thread takes both sorted sub-arrays and the their averages as parameters. It then merges them into a single sorted array in a linear time (so don't call sorting function again! You can simply have a loop and take the smallest from the sorted arrays until they are all merged!), and simply find the overall average by taking the average of the given two averages (this will work because we assume both sub-arrays have the same size!).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!