1.

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

Answer»

Right option is (a) 5 and 4

Best EXPLANATION: Since the INPUT array is not SORTED, bubble sort takes 5 iterations and selection sort takes 4(n-1) iterations.



Discussion

No Comment Found

Related InterviewSolutions