11,595 views
1 1 vote
Suppose we are sorting an array of ten integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 1 2 3 4 5 0 6 7 8 9 Which statement is correct? (Note: Our selection sort picks largest items first.)

A) The algorithm might be either selection sort or insertionsort.

B) The algorithm might be selection sort, but could not be insertion sort.

C) The algorithm might be insertion sort, but could not be selection sort.

D) The algorithm is neither selection sort nor insertion sort.

1 Answer

1 1 vote

Well, Algorithm can be both Selection sort and Insertion Sort.  (hence option A)

Insertion Sort : if the original array is $4,3,2,1,5,0,6,7,8,9$, then after 4 iterations of insertion sort, we get $1,2,3,4,5,0,6,7,8,9$.

Selection Sort : We pick the largest element of the array and place it towards the end, and after doing this $n$ times array is sorted. As, last 4 elements hold this property that at the end of each iteration an element should be towards end. Hence, it can be selection sort (modified). Since this selection sort starts with the largest items, the fully-sorted segment would actually grow from the back of the list.

edited by
Position:
Show:

Related questions

0 0 votes
2 2 answers
1.3k
1.3k views
Pranabesh Ghosh 1 asked Aug 30, 2016
1,278 views
Given an array of integers what is the worst case time complexity that would find pair of integers which are same?A) O(nlogn)B) O(n)C) O()D) O(nloglogn)
4 4 votes
1 answers 1 answer
1.3k
1.3k views
Pranabesh Ghosh 1 asked Aug 30, 2016
1,313 views
A min heap with 1000 elements is stored in an array. What is the maximum possible index number for 9th min element?A) 254B) 100C) 9D) 511
2 2 votes
1 answers 1 answer
1.4k
1.4k views
Pranabesh Ghosh 1 asked Aug 30, 2016
1,395 views
Suppose that an application have a huge number of insert operations, but only few delete max operations. Which priority-queue implementation would be most effective:A) Ma...
0 0 votes
1 1 answer
543
543 views
Pranabesh Ghosh 1 asked Aug 30, 2016
543 views
What is the time complexity to check whether an array is binary min heap or not?A) (n)B) (logn)C) (nlogn)D) (