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 and divides it into two smaller arrays of equal size. It then passes each subarray to sortingavg thread creates two copies of the same thread and waits until these two subarrays are sorted and the average of the values in each array are computed. It then calls mergingavg thread by passing the already sorted two subarrays, and the averages of the first and second subarrays as parameters.
Sortingavg thread sorts the given subarray 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 subarray and its average.
Mergingavg thread takes both sorted subarrays 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 subarrays have the same size!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
