Explanation:- The above statement can not be proved,Because,any deterministic comparison-based sorting algorithm must perform Ω(n log n) comparisons to sort n elements in the worst case. Specifically, for any deterministic comparison-based sorting algorithm A, for all n ≥ 2 there exists an input I of size n such that A makes at least log2 (n!) = Ω(n log n) comparisons to sort I.
For half of the n! inputs:- h ≥ log(n!/2) = logn! - log2 ≥ n*logn - n*loge – 1 = Ω(nlogn)
For Fraction of 1/n inputs:- log(n!/n) = logn! - logn ≥ n*logn - n*loge – logn = Ω(nlogn)
Similarly,
For Fraction of 1/2n inputs:-
log(n!/2n) = logn! – log2n
= logn! – n ≥ n*logn - n*loge – n = Ω(nlogn)
From all the above statements ,we can conclude that there exists comparison based algorithm whose running time is Ω(nlogn) but not linear for at least .a fraction of 1/2n of the n! possible input instances of length n.
Proof of Comparison based sorting algorithm:-
let S be the set of these inputs that are consistent with the answers to all comparisons made so far (so, initially, |S| = n!). We can think of a new comparison as splitting S into two groups: those inputs for which the answer would be YES and those for which the answer would be NO. Now, suppose an adversary always gives the answer to each comparison corresponding to the larger group. Then, each comparison will cut down the size of S by at most a factor of 2. Since S initially has size n!, and by construction, the algorithm at the end must have reduced |S| down to 1 in order to know which output to produce, the algorithm must make at least log2 (n!) comparisons before it can halt. We can then solve:
log2 (n!) = log2 (n) + log2 (n − 1) + ... + log2 (2) = Ω(n log n).
(30 points) Prove or disprove the following statement: There exists a comparison-based sorting algorithm whose running...
Suppose we have an algorithm A that does comparison-based sorting. Answer true or false for each of the following. Assume our input size is n, and that each of the n inputs is distinct. 1. There can be an input ordering for which algorithm A executes no more than n comparisons to determine the sorted order. 2. There can be an input ordering for which algorithm A executes no more than 2n comparisons to determine the sorted order. 3. There...
9-2. For each of the following problems: design a reduction algorithm a hash table or sorting algorithm that solves the problem; describe your algorithm with clear pseudocode; and prove the time efficiency class of your algorithm. duplicate search problem input: a vector V of comparable objects output: an element of V that appears more than once in V, or None if no such element exists 9-2. For each of the following problems: design a reduction algorithm a hash table or...
3. (20 points) Prove the best case performance of comparison-based sortings is S2(nlgn) by using the decision tree approach as a representation of all the possible permutations of the results of sorting. FYI Stirling's approximation, n!> (n/e)".
a) Prove that running time T(n)=n3+30n+1 is O(n3) [1 mark] b) Prove that running time T(n)=(n+30)(n+5) is O(n2) [1 mark] c) Count the number of primitive operation of algorithm unique1 on page 174 of textbook, give a big-Oh of this algorithm and prove it. [2 mark] d) Order the following function by asymptotic growth rate [2 mark] a. 4nlogn+2n b. 210 c. 3n+100logn d. n2+10n e. n3 f. nlogn
1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...
5. [30 pts.] Sorting: Fundamentals (a) [10 pts.] llustrate the performance of the merge-sort algorithm by providing the merge- sort tree T corresponding to (1) the input sequence processed and (2) the output sequence generated based on the following input sequence: (20, 17,5,9, 19,40, 60, 11) i. Phase 1: input sequences processed at each node of T ii. Phase 2: output sequences generated at each node of T We were unable to transcribe this image(c) [10 pts.] Illustrate the performance...
2. Here is a sorting algorithm that I like to use. Given an unsorted list of size n, let Xx represent the data in location k of the unsorted list. Compare xi to X2 and switch if necessary so that they are in sorted order, smallest first. Compare Xn-1 and Xn and switch if necessary so that they are in sorted order, smallest first. • Compare x3 with its left neighbors, switching if necessary so that the 3 first entries...
1. Consider the following well-known sorting algorithm, which is studied later in the book, with a counter inserted to count the number of key comparisons. ALGORITHM SortAnalysis(A[0..n − 1]) //Input: An array A[0..n − 1] of n orderable elements //Output: The total number of key comparisons made count ←0 for i ←1 to n − 1 do v ←A[i] j ←i − 1 while j ≥ 0 and A[j ]> v do count ←count + 1 A[j + 1]←A[j ]...
8. Design a flowchart for sorting the following numbers using "Bubble Sort" algorithm. (20) 74 101 5 [74 10 1 5; N= length of array, a Hints: There are 5 (five) numbers. Let us assume the array, a Start drawing the flowchart as follows: Start For Input ac[74 10 1 5) Length of a False For k-0kcN-2:k-k+1 True 8. Design a flowchart for sorting the following numbers using "Bubble Sort" algorithm. (20) 74 101 5 [74 10 1 5; N=...
Inal Examination 17. Which of the sorting algorithms listed below has the time fastest best case run (a) Heap sort (b) Merge sort (c) Quick sort (d) Insertion sort 18. Which statement below is false: (a) Quick uick sort and merge sort are divide and conquer algorithte (b) Counting sort is a linear time sorting algorithm. (e) Insertion sort and quicksort have similar best case (d) Generic minimum spanning tree algorithm is 19. Counting sort and radix sort are linked...