in Algorithms retagged by
2,731 views
1 vote
1 vote

Selection sort, quick sort is a stable sorting method

  1. True,True
  2. False,False
  3. True,False
  4. False,True
in Algorithms retagged by
2.7k views

4 Answers

2 votes
2 votes

  (B) False, False

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 array to be sorted.

Quick Sort and Selection Sort  are not stable because it swaps non-adjacent elements.

Example: Given [2, 2, 1], the '2' values will not retain their initial order.

2 votes
2 votes

The stability of a sorting algorithm is concerned with how the algorithm treats equal (or repeated) elements. Stable sorting algorithms preserve the relative order of equal elements, while unstable sorting algorithms don’t. In other words, stable sorting maintains the position of two equals elements relative to one another.

 

Several common sorting algorithms are stable by nature, such as Merge SortTimsortCounting SortInsertion Sort, and Bubble Sort. Others such as QuicksortHeapsort and Selection Sort are unstable.

0 votes
0 votes
option B )False,False , both selection sort and quick sort are not stable because the relative ordering of elements is not maintained in both the cases.
0 votes
0 votes

(B).False, False

In selection sort algorithm smallest element in unsorted array is shifted to its correct position in an array. The number of times sorting takes place will always be one less than the number of integer elements in an array.

https://www.flowerbrackets.com/selection-sort-java/

Basically quicksort is a divide and conquer algorithm. Quicksort is one of the widely used sorting algorithm. Because it is used to sort large datasets or lists.

https://www.flowerbrackets.com/quicksort-java/

Answer:

Related questions