Suppose you are given a sequence or array of n real numbers: (a1, a2, . . . , an
ID: 3708846 • Letter: S
Question
Suppose you are given a sequence or array of n real numbers: (a1, a2, . . . , an). We are interested in sorting this list, and ideally sorting it as efficiently as possible / with minimal effort. We can summarize the total ordering information in terms of a permutation of the numbers 1 to n. For instance, given (a1, a2, a3), a total ordering permutation of 3, 1, 2 would tell us that a3 <= a1 <= a2, and therefore that the sorted form of the list would be (a3, a1, a2).
1) How many possible total ordering permutations are there?
2) Argue that if you know or are given the total ordering permutation, then you can sort the list without any additional comparisons or tests.
3) Argue that if you don’t know the total ordering permutation (or only know partial / incomplete information about it), you cannot sort the list without additional comparisons or tests.
4) Taking this view, argue that any sorting algorithm must do at least enough work to determine the total order permutation of the list.
5) If every element comparison (testing whether ai <= aj ) provides one bit of information, argue you need at least on the order of ln(n!) many tests/comparisons to sort the list.
Explanation / Answer
Solution:
1)
So in the array there are n distnict elelments this means that the number of total ordering permutations available are n!
2)
If we are given with the total ordering permutations then within that permutation there is one permutation in which al the elements of the array are sorted, just select that permuation and we are done, this will be done without any comparison and the array will be sorted in tO(1) time.
3)
Yes, if this case we need to see the number of inversions required to see the array and based on whatever knowledge of the permutations we have we can select the permutation which reuqires miniml inversions, insersion sort can do best here.
4)
Yes, as stated above the insersion sort will be running only the number or we say minimum number of passes which are required to sort the given array.
5)
True, this will be like applying Merge sort or quick sort in the array and since n! is considered as n^n according to String's approximation the e=given expression is equivalent to n log n.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.