The Gateway to Computer Science Excellence
+1 vote
The algorithm that will efficiently sort an array that is nearly sorted except for the interchange of some adjacent pairs of numbers like : { 1, 3, 2, 5, 4, 6} is:
(A) Quick sort               (B) Bubble sort
(C) Merge sort              (D) Selection sort


in DS by Boss (49.4k points) | 461 views

1 Answer

+1 vote
should it be B
by Boss (49.4k points)
why not merge sort?
since list is nearly sorted so by using bubble  sort very few exchanges say 2 or   3 will do the job while for merge sort whole array has to be divided and then again merged in addition to comparison and all
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,833 questions
57,713 answers
107,715 users