Double Insertion Sort is a variation on Insertion Sort that works from the middle of the array out. After each iteration, some middle portion of the array is sorted. On the next iteration, take the two adjacent elements to the sorted portion of the array. If they are out of order with respect to each other, then swap them. Now, push the left element toward the right in the array so long as it is greater than the element to its right, and push the right element toward the left in the array so long as it is less than the element to its left. The algorithm begins by processing the middle two elements of the array if the array length is even. If it is odd, then skip processing the middle item and begin with processing the elements to its immediate left and right. a) Find the worst-case cost (in terms of number of comparisons) of Double Insertion Sort and compare it to the worst-case cost of the standard Insertion Sort. b) ( Implement Double Insertion Sort. Make sure you handle properly both cases when the array length is odd and when it is even. ) Compare its running time in practice against standard Insertion Sort. For this purpose, measure the running time in milliseconds of the 2 implementations for N= 10000, 20000, 40000, 80000 and 160000. For each data size N, generate a random list of N random integers ranging from 1 to 107 and use the same list to measure the running time of the 2 implementations. Take the average of 3 measurements and present the results in the following table: Pivot N-10000 N-20000 N-40000 N-80000 N=160000 Insertion sort Double insertion sort d) (- Plot the obtained running time results of the two algorithms in the same chart.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 3RQ
icon
Related questions
Question

Subject: Data structure 

Double Insertion Sort is a variation on Insertion Sort that works from the middle of the array out.
After each iteration, some middle portion of the array is sorted. On the next iteration, take the two
adjacent elements to the sorted portion of the array. If they are out of order with respect to each
other, then swap them. Now, push the left element toward the right in the array so long as it is
greater than the element to its right, and push the right element toward the left in the array so long
as it is less than the element to its left. The algorithm begins by processing the middle two
elements of the array if the array length is even. If it is odd, then skip processing the middle item
and begin with processing the elements to its immediate left and right.
a)
Find the worst-case cost (in terms of number of comparisons) of Double
Insertion Sort and compare it to the worst-case cost of the standard Insertion Sort.
b) (
Implement Double Insertion Sort. Make sure you handle properly both cases
when the array length is odd and when it is even.
») Compare its running time in practice against standard Insertion Sort. For this
purpose, measure the running time in milliseconds of the 2 implementations for N=10000,
20000, 40000, 80000 and 160000. For each data size N, generate a random list of N random
integers ranging from 1 to 10' and use the same list to measure the running time of the 2
implementations. Take the average of 3 measurements and present the results in the
following table:
Pivot
N-10000 N-20000 | N-40000 N-80000 N=160000
Insertion sort
Double insertion sort
d) (-
Plot the obtained running time results of the two algorithms in the same chart.
Transcribed Image Text:Double Insertion Sort is a variation on Insertion Sort that works from the middle of the array out. After each iteration, some middle portion of the array is sorted. On the next iteration, take the two adjacent elements to the sorted portion of the array. If they are out of order with respect to each other, then swap them. Now, push the left element toward the right in the array so long as it is greater than the element to its right, and push the right element toward the left in the array so long as it is less than the element to its left. The algorithm begins by processing the middle two elements of the array if the array length is even. If it is odd, then skip processing the middle item and begin with processing the elements to its immediate left and right. a) Find the worst-case cost (in terms of number of comparisons) of Double Insertion Sort and compare it to the worst-case cost of the standard Insertion Sort. b) ( Implement Double Insertion Sort. Make sure you handle properly both cases when the array length is odd and when it is even. ») Compare its running time in practice against standard Insertion Sort. For this purpose, measure the running time in milliseconds of the 2 implementations for N=10000, 20000, 40000, 80000 and 160000. For each data size N, generate a random list of N random integers ranging from 1 to 10' and use the same list to measure the running time of the 2 implementations. Take the average of 3 measurements and present the results in the following table: Pivot N-10000 N-20000 | N-40000 N-80000 N=160000 Insertion sort Double insertion sort d) (- Plot the obtained running time results of the two algorithms in the same chart.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Counting Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage