Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started