In JAVA code (Insertion Sort):  1. Prepare a data set containing 10,000 integers (random). 2. Make a code that will create 3 variants of the data: one in best case (data are arranged in ascending order); the other in worst case (data are arranged in descending order); and the last in average case (data are randomly arranged). 3. Each integer is considered as one input in the code.  4. The output of your program should be the number of statements executed in the process of sorting for each of the algorithms. This, therefore, means that you have to embed a counter variable in your program that keeps track of the number of statements executed in the sorting part of your code. 5. The end value of the variable shall be the output of your program. Below is a sample of the code in Bubble Sort; I am asking for the program for insertion sort.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In JAVA code (Insertion Sort): 

1. Prepare a data set containing 10,000 integers (random).

2. Make a code that will create 3 variants of the data: one in best case (data are arranged in ascending order); the other in worst case (data are arranged in descending order); and the last in average case (data are randomly arranged).

3. Each integer is considered as one input in the code. 

4. The output of your program should be the number of statements executed in the process of sorting for each of the algorithms. This, therefore, means that you have to embed a counter variable in your program that keeps track of the number of statements executed in the sorting part of your code.

5. The end value of the variable shall be the output of your program.

Below is a sample of the code in Bubble Sort; I am asking for the program for insertion sort.

 

1 usage
public static long ascendingBubbleSort(long[] array) {
long count
}
=
count++; // count for int i = 0 since i = 0 is only executed once
for (int i = 0; i < array.Length 1; i++){
count += 2; // count for i < array.length; i++
count++; //count for j = 0
}
for (int i =
0;
}
0; j < array.Length i 1; j++) {
count += 4; // count for j < array.length i 1; j++
if (array[j] > array[j + 1]) {
count += 4; // count for array[j] > array[j + 1]
int temp = (int) array[j];
count += 2; // count for int temp = (int) array[j]
array[j] = array[j + 1];
count += 4; // count for array[j]
array[j+ 1] = temp;
count += 3; // count for array[j+1] = temp
}
return count;
=
array[j+1]
Transcribed Image Text:1 usage public static long ascendingBubbleSort(long[] array) { long count } = count++; // count for int i = 0 since i = 0 is only executed once for (int i = 0; i < array.Length 1; i++){ count += 2; // count for i < array.length; i++ count++; //count for j = 0 } for (int i = 0; } 0; j < array.Length i 1; j++) { count += 4; // count for j < array.length i 1; j++ if (array[j] > array[j + 1]) { count += 4; // count for array[j] > array[j + 1] int temp = (int) array[j]; count += 2; // count for int temp = (int) array[j] array[j] = array[j + 1]; count += 4; // count for array[j] array[j+ 1] = temp; count += 3; // count for array[j+1] = temp } return count; = array[j+1]
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY