Answer: -------- 4 7 8 12 8 15 17 19 23 Explanation: ------------- Array after iteration 1 is [7, 19, 12, 4, 8, 17, 15, 8, 23] Array after iteration 2 is [7, 12, 4, 8, 17, 15, 8, 19, 23] Array after iteration 3 is [7, 4, 8, 12, 15, 8, 17, 19, 23] Array after iteration 4 is [4, 7, 8, 12, 8, 15, 17, 19, 23] Array after iteration 5 is [4, 7, 8, 8, 12, 15, 17, 19, 23] Array after iteration 6 is [4, 7, 8, 8, 12, 15, 17, 19, 23] Array after iteration 7 is [4, 7, 8, 8, 12, 15, 17, 19, 23] Array after iteration 8 is [4, 7, 8, 8, 12, 15, 17, 19, 23]
Question 3 QUESTION //Sort the array arr[] for (int i = 0; i< arr.length - 1;...
QUESTION: //Sort the array arr[] for (int i = 0; i < arr.length - 1; i++) { //outer int index = i; for (int j = i + 1; j < arr.length; i++) if (arr[j] < arr[index]) index = j; int smallerNumber = arr[index]; arr[index] = arr[i]; arr[i] = smallerNumber; }//for i In the array= 16 13 15 14 19 24 9 3, the index of the smallest number at the outer iteration 4 = Answer
Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first iteration? Given an insertion sort and the following array: [50,5,35,70,6] What does the array look like after the first insertion: Fill in the missing code for InsertionSort method // Insertion Sort method //sorts an array of Auto objects public static void insertionSort(Auto [] arr) { Auto temp; int j; for (int i=1; i<arr.length; i++) { j=i; temp=arr[i]; while (j!=0 &&(temp.getModel().compareTo(arr[[j-1].getModel())<0)...
[5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9, 4, 3). Assuming we call the following function using statement selection sort (int array, 7); Please fill the table to show the changes of the array int_array after each iteration. The first column is filled. void selection_sort (int list[], int list_size) for (int i = 0; i < list size - 1; 1++) int current min = list[1]; int current_min_index-i for (int j -...
I need to program 3 and add to program 2 bellows: Add the merge sort and quick sort to program 2 and do the same timings, now with all 5 sorts and a 100,000 element array. Display the timing results from the sorts. DO NOT display the array. ____________________>>>>>>>>>>>>>>>>>>>>___________________________ (This is program 2 code that I did : ) ---->>>>>> code bellow from program 2 java program - Algorithms Write a program that randomly generates 100,000 integers into an array....
must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...
4. Use the Insertion Sort algorithm to sort the following array in nondecreasing order. arr = { 896 745 23 } a. Show the order of the array after every i-loop iteration. (4 points) b. How many comparisons are made for this specific array? (1 point) C. State the best, worst, and average-case performance of Insertion Sort. (1 point)
Question 9 0 Consider the following method. public static String[] strArrMethod(String] arr) String[] result = new String(arr.length]; for (int j - 0; j < arr.length; j++) String sm = arr[i]; for (int k = j + 1; k < arr.length; k++) if (arr[k].length() < sm.length) sm - arr[k]; // Line 12 result[j] = SM; return result; Consider the following code segment. String[] test Two - {"last", "day" of "the", school","year"); String[] resultTrostrar Method(test Two) How many times is the line...
I want to compare the runtimes and swap operations times among quick Sort, selection Sort and shell Sort here is my code: But when I create a 1000,000 size array, I can't get the result of the operations times and runtime. what's wrong with my code? and I also want to copy the array. Because I want to use same array for three sort. And for the shell Sort, I haven't learn it in my class. Can anyone help me...
public static int max(int [] arr){ int max = arr[0]; for( int i = 1; i < arr.length; i++ ) if( arr[i] > max ) max = arr[i]; return max; } 1) Provide an input value for arr that causes the method to throw an IndexOutOfBounds exception. 2) Provide an input value for arr that causes the method to throw a NullPointerException.
Student Name Student ID CS209 Data Structures and Algorithms - Quiz 1/2e Friday, Feb 22, 2019 1. (25 points) Here is an array of five integers: 5,3,4,2,1 Please draw this array after EACH iteration of the large loop (outer loop) in a Bubble sort (sorting smallest to largest). (25 points) Here is an array of five integers: 5,3,4,2,1 Please draw this array after EACH iteration of the large loop (outer loop) in a Selection sort (sortin from smallest to largest)....