Sorting
Q31.
A list of n strings, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation isQ32.
What is the number of swaps required to sort n elements using selection sort, in the worst case?Q33.
Choose the correct alternatives (more than one may be correct) and write the corresponding letters only: Following algorithm(s) can be used to sort n in the range [1\ldots n^3] in O(n) timeQ34.
Suppose you are provided with the following function declaration in the C programming language. int partition(int a[ ], int n); The function treats the first element of a[] as a pivot, and rearranges the array so that all elements less than or equal to the pivot is in the left part of the array, and all elements greater than the pivot is in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part. The return value is the number of elements in the left part. The following partially given function in the C programming language is used to find the k^{th} smallest element in an array a[ ] of size n using the partition function. We assume k \leq n int kth_smallest(int a[], int n, int k) { int left_end = partition(a,n); if ( left_end+1 == k ){ return a[left_end]; } if ( left_end+1 > k ){ return kth_smallest( ________ ); } else { return kth_smallest( ________ ); } } The missing argument lists are respectivelyQ35.
Which one the following in place sorting algorithms needs the minimum number of swaps?Q39.
The usual \Theta (n^{2}) implementation of Insertion Sort to sort ab array uses linear search to identify the position where an element is to be inserted into the already sorted part of the array. If, instead, we use binary search to identify the position, the worst case running time willQ40.
Quick-sort is run on two inputs shown below to sort in ascending order taking first element as pivot (i). 1, 2, 3, \dots n (ii). n, n-1, n-2, \dots, 2, 1 Let C_1 and C_2 be the number of comparisons made for the inputs (i) and (ii) respectively. Then,