in Algorithms edited by
1,613 views
0 votes
0 votes
Consider the following scenario during insertion sort when the array looks like the following:

{25,75,95,125,80,5,10}

The number of comparisons that it will further take for the array to be completely sorted are______?
in Algorithms edited by
1.6k views

4 Comments

@Deepanshu Yes now it got cleared..Thank u :)
0
0
The question uses the word "during" insertion sort, "further" comparisons and then the solution doesn't consider them!! :/

Also it is not clear as up to which element comparison has been done. I mean if the initial array was like {75,25,95,125,80,5,10} then 1st iteration will take key as 25 and make the array like  {25,75,95,125,80,5,10} (i.e. the one given in the question). If this is the case then we have to start solving by taking key=95.

Though at first I also assumed key to be 80.

To me it is not a well framed question :/
0
0
@MiniPanda Yes they shouldnt have mentioned the line "further comparisons needed"..instead just asking the number of comparisons required for insertion sort on the given array wouldn't have led to any confusion!
0
0

2 Answers

2 votes
2 votes
Getting 17 as the answer. Questioner should confirm

1 comment

ya 17 is the answer
0
0
0 votes
0 votes

It is given that “The number of comparisons that it will further take for the array to be completely sorted are”

Hence it means that some of the array was already sorted (first 4 elements).

Hence I think we need to answer the no of comparison for the last unsorted elements,

Related questions