SelectionSort

The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array … More on Selection Sort

1
 Question 1
Consider a situation where swap operation is very costly. Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general?
 A Heap Sort B Selection Sort C Insertion Sort D Merge Sort
Sorting    SelectionSort    InsertionSort    MergeSort
Discuss it

Question 1 Explanation:

Selection sort makes O(n) swaps which is minimum among all sorting algorithms mentioned above.

 Question 2
Which sorting algorithm will take least time when all elements of input array are identical? Consider typical implementations of sorting algorithms.
 A Insertion Sort B Heap Sort C Merge Sort D Selection Sort
Sorting    SelectionSort    InsertionSort    MergeSort
Discuss it

Question 2 Explanation:
The insertion sort will take (n) time when input array is already sorted.
 Question 3
Which of the following sorting algorithms has the lowest worst-case complexity?
 A Merge Sort B Bubble Sort C Quick Sort D Selection Sort
Analysis of Algorithms    Sorting    SelectionSort    MergeSort
Discuss it

Question 3 Explanation:
Worst case complexities for the above sorting algorithms are as follows: Merge Sort — nLogn Bubble Sort — n^2 Quick Sort — n^2 Selection Sort — n^2
 Question 4
Which is the correct order of the following algorithms with respect to their time Complexity in the best case ?
 A Merge sort > Quick sort >Insertion sort > selection sort B insertion sort < Quick sort < Merge sort < selection sort C Merge sort > selection sort > quick sort > insertion sort D Merge sort > Quick sort > selection sort > insertion sort
Sorting    QuickSort    SelectionSort    InsertionSort
Discuss it

Question 4 Explanation:
In best case,

Quick sort: O (nlogn)
Merge sort: O (nlogn)
Insertion sort: O (n)
Selection sort: O (n^2)  
 Question 5
Which one of the following in-place sorting algorithms needs the minimum number of swaps?
 A Insertion Sort B Quick Sort C Heap Sort D Selection Sort
SelectionSort    ISRO CS 2017 - May
Discuss it

Question 5 Explanation:
Selection Sort is an in-place algorithm having minimum number of swaps. It works on greedy approach and takes O(n) swaps to sort the array of n elements. Refer: GATE-CS-2006 | Question 14
 Question 6
How many comparisons are needed to sort an array of length 5 if a straight selection sort is used and array is already in the opposite order?
 A 1 B 5 C 10 D 20
SelectionSort    ISRO CS 2008
Discuss it

Question 6 Explanation:
Consider the array: 5 4 3 2 1 1st iteration will compare 4 numbers with the 5 2nd iteration will compare 3 numbers with the 4 3rd iteration will compare 2 numbers with the 3 4th iteration i will compare 1 number with the 2 So, the total number of comparisons is 4 + 3 + 2 + 1 = 10 It can be viewed as the sum of the sequence of the first (n-1) numbers starting by 1 S = ((1 + (n-1) )*(n-1) )/2 S = 10 Option (C) is correct.
There are 6 questions to complete.
1

Coding practice for sorting.

My Personal Notes arrow_drop_up