How many comparisons between values of and x actually occur when insertion sort is applied to the array of exercise 21?
To find the no of total comparison between a[j] and x using algorithm segment.
From the given
Initially given 5 elements and 5 is assigned to n. Initially set k to 2, x to a[k]= a=3 and j to k-1=2-1=1.Here, .
First step to compare the second element 3 which is less than first element 7 ,so need to assign the 7 as the second element and then j is decreased by 1.One comparison between x and a[j],followed by comparison (stops the while loop as j=0) next assign the 3 as a first element
Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!Get Started