Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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