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 \theta(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)  
There are 4 questions to complete.
1

 

Coding practice for sorting.

 

Company Wise Coding Practice    Topic Wise Coding Practice