1.

The given array is arr = {1,2,3,4,5}. (bubble sort is implemented with a flag variable)The number of iterations in selection sort and bubble sort respectively are __________(a) 5 and 4(b) 1 and 4(c) 0 and 4(d) 4 and 1The question was posed to me in a job interview.Query is from Selection Sort in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct option is (d) 4 and 1

The best I can EXPLAIN: SELECTION sort is insensitive to input, HENCE 4(n-1) ITERATIONS. Whereas bubble sort iterates only once to set the flag to 0 as the input is already sorted.



Discussion

No Comment Found

Related InterviewSolutions