Explanation: In the insertion sort , just imagine that the first element is already sorted and all the right side Elements are unsorted, we need to insert all elements one by one from left to right in the sorted Array. Sorted : 5 unsorted : 4321 Insert all elements less than 5 on the left (Considering 5 as the key ) Now key value is 4 and array will look like this Sorted : 4 5 unsorted Similarly for all the cases the key will always be the newly inserted value and all the values will be compared to that key and inserted in to proper position.
Answers
Answer: You insert the new card in the right place, and once again, your hand holds fully sorted ... Notice that the slide operation just copies the element one position to the right. ... Insertion sort repeatedly inserts an element in the sorted subarray to its left. ... After 0,1000 are sorted, all the rest of the elements will start from the left
Explanation: please mark me as brilliant
Answer:
Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array.
(A) 4 5 3 2 1
3 4 5 2 1
2 3 4 5 1
1 2 3 4 5
(B) 5 4 3 1 2
5 4 1 2 3
5 1 2 3 4
1 2 3 4 5
(C) 4 3 2 1 5
3 2 1 5 4
2 1 5 4 3
1 5 4 3 2
(D) 4 5 3 2 1
2 3 4 5 1
3 4 5 2 1
1 2 3 4 5
Answer: (A)
Explanation: In the insertion sort , just imagine that the first element is already sorted and all the right side Elements are unsorted, we need to insert all elements one by one from left to right in the sorted Array.
Sorted : 5 unsorted : 4 3 2 1
Insert all elements less than 5 on the left (Considering 5 as the key )
Now key value is 4 and array will look like this
Sorted : 4 5 unsorted : 3 2 1
Similarly for all the cases the key will always be the newly inserted value and all the values will be compared to that key and inserted in to