Dark Mode

2,731 views

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

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 Sort, Timsort, Counting Sort, Insertion Sort, and Bubble Sort. Others such as Quicksort, Heapsort and Selection Sort are unstable.

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.