edited by
698 views
1 votes
1 votes

Is below problem meaningful? I am not able to get any logic behind it. Either am missing something or the problem is real crap.

Suppose one is applying a particular quadratic sorting algorithm to an array of integers. After four iterations the array stand as:
1,2,3,4,5,6,7,8,9

Which of the following may be in use?

  1. Selection sort that selects the largest element in each iteration
  2. Insertion sort
    1.  i or ii
    2. ii only
    3. ii only
    4. None of these
edited by

1 Answer

4 votes
4 votes

Its a perfectly Logical Question

To understand this question, you have to understand the logic behind the Selection Sort and Insertion Sort.

Selection Sort: In the first iteration it select the first element of the array (say p), and compare p to the rest of the element in the array. And if there is any element exist which is greater than then it perform a swap and again start comparing with the new value of p.

The given sequence (1, 2, 3, 4, 5, 6, 7, 8) can not be achieved by using Selection Sort (In the question its given that it select largest element in each iteration). Because  this will put 8 on the first position after the first iteration. But 8 is in the end. Hence it can not possible. 

Insertion Sort : This is based on the partition. Lets take sequence as 4,2,3,1,5,6,7,8 and apply insertion sort. After 4 iteration you will get 1,2,3,4,5,6,7,8. (I am taking this because in the question its not given that insertion is sorting element in increasing order or decreasing order). 

Hence Answer would be (B) ii Only

Related questions

2 votes
2 votes
1 answer
1
smartmeet asked Jan 13, 2017
563 views
If possible,. all 3 cases (best,average, worst)