Knowee
Questions
Features
Study Tools

Assume we want to sort integers into ascending order. To sort a small array that contains 42, 17, insertion sort will perform three assignments. How many assignments will insertion sort perform to sort an array that contains these 10 elements: 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ? Group of answer choices 15 18 24 55 63

Question

Assume we want to sort integers into ascending order. To sort a small array that contains 42, 17, insertion sort will perform three assignments. How many assignments will insertion sort perform to sort an array that contains these 10 elements: 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ? Group of answer choices

15

18

24

55

63

🧐 Not the exact question you are looking for?Go ask a question

Solution

Insertion sort works by building a sorted array one item at a time, with the movement of higher-ranked elements necessary to make room for the new element.

In the worst-case scenario, which is a reverse sorted array, insertion sort performs n*(n+1)/2 assignments, where n is the number of elements in the array. This is because for each new element, the algorithm may have to move all the previously sorted elements.

So, for an array of 10 elements, insertion sort will perform 10*(10+1)/2 = 55 assignments.

Therefore, the correct answer is 55.

This problem has been solved

Similar Questions

Assume we want to sort integers into ascending order. To sort a small array that contains 42, 17, selection sort will perform one swap, or three assignments. How many assignments will it perform to sort an array that contains these 10 elements: 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ? Group of answer choices 15 18 24 27 63

What will be the number of passes to sort the elements using insertion sort?14, 12,16, 6, 3, 10

Select the correct answerWhat will be the number of passes to sort 14, 12,16, 6, 3, 10 using insertion sort?Options6715

SortingOne common task for computers is to sort data. For example, people might want to see all their files on a computer sorted by size. Since sorting is a simple problem with many different possible solutions, it is often used to introduce the study of algorithms.Insertion SortThese challenges will cover Insertion Sort, a simple and intuitive sorting algorithm. We will first start with a nearly sorted list.Insert element into sorted listGiven a sorted list with an unsorted number in the rightmost cell, can you write some simple code to insert into the array so that it remains sorted?Since this is a learning exercise, it won't be the most efficient way of performing the insertion. It will instead demonstrate the brute-force method in detail.Assume you are given the array indexed . Store the value of . Now test lower index values successively from to until you reach a value that is lower than , at in this case. Each time your test fails, copy the value at the lower index to the current index and print your array. When the next lower indexed value is smaller than , insert the stored value at the current index and print the entire array.ExampleStart at the rightmost index. Store the value of . Compare this to each element to the left until a smaller value is reached. Here are the results as described:1 2 4 5 51 2 4 4 51 2 3 4 5Function DescriptionComplete the insertionSort1 function in the editor below.insertionSort1 has the following parameter(s):n: an integer, the size of arr: an array of integers to sortReturnsNone: Print the interim and final arrays, each on a new line. No return value is expected.Input FormatThe first line contains the integer , the size of the array .The next line contains space-separated integers .ConstraintsOutput FormatPrint the array as a row of space-separated integers each time there is a shift or insertion.Sample Input52 4 6 8 3Sample Output2 4 6 8 8 2 4 6 6 8 2 4 4 6 8 2 3 4 6 8 Explanation is removed from the end of the array.In the st line , so is shifted one cell to the right.In the nd line , so is shifted one cell to the right.In the rd line , so is shifted one cell to the right.In the th line , so is placed at position .Next ChallengeIn the next Challenge, we will complete the insertion sort.

Illustrate the operations of the New Insertion sort algorithm for the array with thegiven set of elements. (For the illustration process assign the values only once to thegiven algorithm codes and then use diagrammatic way to reach the answer.)NEW-INSERTION-SORT (A)1 for j = 2 to A.length2. i =13. while A[j] > A[i]4. i = i + 15 key = A[j]6 for k = 0 to j - i - 17 A[j-k] = A[j-k-1]8 A[i] = key

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.