1.

How many iterations are required to sort the array arr={2,3,4,5,1} using bubble sort and cocktail sort respectively?(a) 4,2(b) 5,3(c) 5,2(d) 4,3The question was posed to me at a job interview.Asked question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (a) 4,2

The best explanation: Cocktail sort applies bubble sort in two phases until the array GETS SORTED. So here bubble sort will take 4 iterations to sort the given array WHEREAS cocktail sort takes only 2 iterations. This shows cocktail sort has a comparatively better PERFORMANCE.



Discussion

No Comment Found

Related InterviewSolutions