Question: ( 2 5 pts ) Consider the Deviation Sorting Problem: Input: An array A = ( : a 1 , a 2 , dots, a

(25 pts) Consider the Deviation Sorting Problem:
Input: An array A=(:a1,a2,dots,an:) of n numbers.
Output: The sorted absolute deviations (in nondecreasing order) of the numbers from the array average.
Ex: Let A=(:3,5,8,10,9:), then the array average ?bar(A)=3+5+8+10+95=7. The absolute deviation di of ai from the array average ?bar(A) can be calculated as di=|ai-(?bar(A))|.
Then, the unsorted absolute deviations array can be given as D=(:4,2,1,3,2:).
We obtain the output as (:1,2,2,3,4:) after sorting the array D in nondecreasing order.
a.(10 pts) Design an algorithm, say Deviation Sorting algorithm, that solves Deviation Sorting Problem. Give the pseudocode of your algorithm. (Hint: You may use a sorting algorithm from the lecture.)
b.(7 pts) Show the iterations step-by-step of your algorithm on the instance in the example.
c.(8 pts) What is the computational complexity of your algorithm? Is it an efficient algorithm or not? Discuss in detail.
( 2 5 pts ) Consider the Deviation Sorting

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 Programming Questions!