MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
If the given input array is sorted or nearly sorted, which of the following algorithm gives the best performance?
A
Insertion sort
B
Bubble sort
C
Merge sort
D
Quick sort
Explanation: 

Detailed explanation-1: -Explanation: If The Given Input Array Is Sorted Or Nearly Sorted, Insertion sort Algorithm Gives The Best Performance. Insertion sort is a simple sorting algorithm that builds the final sorted array one item at a time.

Detailed explanation-2: -When the array is almost sorted, insertion sort can be preferred. When order of input is not known, merge sort is preferred as it has worst case time complexity of nlogn and it is stable as well. When the array is sorted, insertion and bubble sort gives complexity of n but quick sort gives complexity of n^2.

Detailed explanation-3: -Many authors, including Knuth and MacLaren, mention that Straight Insertion Sort is the best sorting algorithm when the list is very nearly in order.

Detailed explanation-4: -Solutions for Which of the following sorting algorithms in its typical implementation gives best performance when applied on an array which is sorted or almost sorted (maximum 1 or two elements are misplaced). a)Quick Sortb)Heap Sortc)Merge Sortd)Insertion SortCorrect answer is option ā€˜Dā€™.

There is 1 question to complete.