edited by
2,986 views
3 votes
3 votes

There are many sorting algorithms based on comparison. The running time of heapsort algorithm is $O(n \text{lg}n)$. Like $P$, but unlike $Q$, heapsort sorts in place where $(P,Q)$ is equal to

  1. Merge sort, Quick sort
  2. Quick sort, insertion sort
  3. Insertion sort, Quick sort
  4. Insertion sort, Merge sort
edited by

2 Answers

2 votes
2 votes

Answer should be (4) Insertion Sort, Merge Sort

Explanation - 

The question asks specifically for in-place sorting algorithms, which means the algorithms in which only $O(1)$ space is used. 

Hence, out of the options - 

Insertion Sort - Sorts in place with worst case time and space complexity of $O(n^2)$ and $O(1)$ respectively.

Heap Sort - Sorts in place with worst case time and space complexity of $O(n \cdot \log n)$ and $O(1)$ respectively.

Merge Sort - Sorts out of place with worst case time and space complexity of $O(n\cdot \log n)$ and $O(n)$ respectively. 

Quick Sort - Sorts in place with worst case time and space complexity of $O(n^2)$ and $O(1)$ respectively. 

 

Now for the given question, P needs to be an in place sorting algorithm, and Q needs to be out of place sorting algorithm, Hence option 4.

Answer:

Related questions

2 votes
2 votes
2 answers
1
Arjun asked Jul 2, 2019
1,666 views
Match List-I with List-II:$$\begin{array}{|c|c|c|c|} \hline {} & \text{List-I} & {} & \text{List-II} \\ \hline (a) & \text{Prim’s algorithm} & (i) & O(V^3 \log V) \\ \h...
7 votes
7 votes
3 answers
2
Arjun asked Jul 2, 2019
3,325 views
Which of the following is best running time to sort $n$ integers in the range $0$ to $n^2-1$?$O(\text{lg } n)$$O(n)$$O(n\text { lg }n)$$O(n^2)$
1 votes
1 votes
1 answer
3
Arjun asked Jul 2, 2019
1,881 views
Which of the following is application of depth-first search?Only topological sortOnly strongly connected componentsBoth topological sort and strongly connected components...
3 votes
3 votes
2 answers
4