-
In a permutation a1……an of n distinct integers, an inversion is a pair (ai, aj) such that i < j and ai > aj. What would be the worst case time complexity of the Insertion Sort algorithm, if the inputs are restricted to permutations of 1……n with at most n inversions?
-
Let P be a Quicksort Program to sort numbers in ascending order using the first element as pivot. Let t1 and t2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds?
t1 = t2
t1 > t2
t1 < t2 -
Which of the following is an external sorting?
Insertion Sort
Merge Sort
Bubble Sort
Tree Sort
4)Partition and exchange sort is ………
Quick Sort
Heap Sort
Bubble Sort
-
The ususal O(n^2) implementation of insertion sort uses the linear search to 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 will be:
O(n)
O(nlogn)
O(n^2)
O(n(logn)^2) -
If quicksort is written so that partition algorithm always uses the median value of the segment as the pivot then worst case performance of quick sort will be?
O(n)
O(nlogn)
O(n^2) -
You have an array of n elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is
O(n^2)
O(nlogn)
O(n)