# Recent questions tagged sorting

0 answers 4 views
Consider th following cases for quick sort to sort an array of n element $a[0...n-1]$ i) Choosing the pivot element randomly from the given array ii) choosing median element as pivot. Iii) Choosing middle element as pivot For which of the above cases quick sort always gives $O(nlogn)$ time complexity?
0 answers 2 views
Consider an array A of length n, array contain number between (1 – 10), in any arbitary order, best sorting algorithm takes $650$ ns if $n = 50$, the time required by algorithm if n = 300.
1 vote
1 answer 14 views
An array is said to be -ordered if for each such that . for example, the array 1 4 2 6 3 7 5 8 is 2-ordered. In a 2-ordered array of 2N elements, what is the maximum number of positions that an element can be from its position if the array were 1-ordered?
0 answers 8 views
Below is the implementation of merge sort. void sort(int a, int lo, int hi){ if(hi<=lo) return; int mid = lo + (hi-lo)/2; sort(a,lo,mid); sort(a,mid+1,hi); merge(a,lo,mid,hi); } Assume that merge function merges the elements a[lo] to a[mid] and a[mid+1] to a[hi]. ... merge() whenever a[mid]<=a[mid+1]. The number of comparisons needed to merge sort a sorted array is: O(n log n) O(n) O(1) O(log n)