Question: Consider arranging 'n' alphabet stored in an array A, by first finding the biggest alphabet of A and exchanging it with the element in

Consider arranging 'n' alphabet stored in an array A, by first finding the biggest alphabet of A and exchanging it with the element in A[n]. Then find the second biggest alphabet of A and exchange it with A[n-1] continue in this manner up to A[2] alphabets. For example, if A="DCBA" then after the first iteration A="ACBD" then find the next biggest alphabet and swap it. In the end the algorithm should return the output as "ABCD". Based on the approach described above, write an algorithm for arranging the given 'n' alphabets in an increasing order of the alphabets and prove the correctness of the algorithm. (7 Marks) Compute the best-case running time, worst-case running time and the average-case running time of the algorithm. Compare this algorithm with that of the insertion-sort algorithm, based on the respective T (n). Based on your analysis, conclude which algorithm performs better for which type of inputs. (3 Marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
