edited by
1,434 views
3 votes
3 votes

A sorting technique is called stable if

  1. If it takes $O(n\log n)$ time.
  2. It uses divide and conquer technique.
  3. Relative order of occurrence of non-distinct elements is maintained.
  4. It takes $O(n)$ space.
edited by

2 Answers

Best answer
4 votes
4 votes

Answer is C

A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input unsorted array.

  • Merge sort, Insertion sort, selection sort etc are stable
  • Heap Sort, Quick Sort and Shell sort are unstable.

Is there any advantage in implementing stable sort?

  • You have a list with information about destination of the flight and departure time.
  • You first sort the list based on time. You then sort it based on destination.
  • If the second sort is stable we now have all flights bound to same destination together and in increasing order of departure time.
selected by
Answer:

Related questions

1 votes
1 votes
2 answers
1
gatecse asked Dec 17, 2017
3,355 views
The characters of the string $\text{K R P C S N Y T J M}$ are inserted into a hash table of the size of size $10$ using a hash function$h(x)=(ord(x)-ord(A)+1)$ $mod$ $10$...
1 votes
1 votes
1 answer
2
gatecse asked Dec 17, 2017
1,871 views
Quick-sort is run on $2$ inputs shown below to sort in ascending order :$1,2,3\ldots n$$n,n-1,n-2\ldots 1$Let $C$1 and $C2$ be the number of comparisons made for A and B ...
4 votes
4 votes
1 answer
3
gatecse asked Dec 17, 2017
1,723 views
Match the following and choose the correct answer for the order $A,B,C,D$$$\begin{array}{|ll|ll|}\hline \text{A.} & \text{Strassen matrix multiplication} & \text{p.} & ...
3 votes
3 votes
2 answers
4
gatecse asked Dec 17, 2017
3,028 views
Consider the recurrence equation$T(n) =\begin{cases}2T(n-1), & \text{if }n>0 \\1, & \text{otherwise}\end{cases}$Then $T(n)$ is (in $big\, O$ order)$O(n)$$O(2^n)$$O(1)$$O(...