Question: //The Driver: public class Lab9Driver { public static void main(String[] args) { int[] arr1 = { 9, 13, 5, 15, 2, 10, 12, 3, 14,

 //The Driver: public class Lab9Driver { public static void main(String[] args){ int[] arr1 = { 9, 13, 5, 15, 2, 10, 12,

//The Driver:

public class Lab9Driver {

public static void main(String[] args) {

int[] arr1 = { 9, 13, 5, 15, 2, 10, 12, 3, 14, 7 }; System.out.print("Original array : ["); print(arr1); System.out.print("Sorted Using Insertion Sort: ["); print(Util.sortInsertion(arr1)); System.out.println(" "); System.out.print("Original array : ["); print(arr1); System.out.print("Sorted Using Selection Sort: ["); print(Util.sortSelction(arr1));

}

private static void print(int[] arr) {

for (int i : arr) { System.out.print(i+" "); } System.out.println("]"); }

}

The textbook showed one way to sort values in Chapter 10, which was selection sort. Insertion sort is another simple sorting algorithm. Insertion sort is an efficient algorithm for sorting a small number of elements. In- sertion sort involves examining each item of the list in turn and placing that item in its proper place among the already sorted elements. Consider arranging a hand of cards as they are dealt to you: you might pick up each card one at a time and insert each card in its proper place amongst the cards in your hand. This is the basic algorithm of insertion sort, which is about the fastest algorithm available for sorting a bunch of data where most (but not all!) of the elements are already in order an extremely important real-world case Pseudocode of the complete algorithm follows, where the arrays are zero-based: for i 1 to length (A) while j 0 and A [j -1] AIj swap A j and A Dj-1] end while end for What to do In this lab, you will implement a Utility class that contains two class methods: int O sortSelction(int array) //implements the selection sort algorithm; modifies a copy of the input array by arranging its elements in ascending order int O sortInsertion(int array)//implements the insertion sort algorithm, modifies a copy of the input array by arranging its elements in ascending order

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!