Question: Consider the following sorting algorithm: 1 : func SELECTION - SORT ( arr ) : 2 : , n = LEN ( a r r
Consider the following sorting algorithm:
: func SELECTIONSORTarr: : LEN : if : : return arr : else: : result SELECTIONSORT : Sort all but the last element : lastelement arr
: let be the first index such that arr lastelement arr
: result.INSERTlastelement, Insert lastelement into correct position
: return result
Prove the correctness of this algorithm by induction.
Write a recurrence, for the runtime of this algorithm. Assume finding in line is done via linear search.
Solve this recurrence in terms of asymptotic complexity, ie find a function such that
How does this recurrence change if we find i via binary search? How does this affect the asymptotic complexity?
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
