Answer: --------- 3 Explanation: ------------- After iteration 1, smallest number is 3 and it's index is 7 Array is [3, 13, 15, 14, 19, 24, 9, 16] After iteration 2, smallest number is 9 and it's index is 6 Array is [3, 9, 15, 14, 19, 24, 13, 16] After iteration 3, smallest number is 13 and it's index is 6 Array is [3, 9, 13, 14, 19, 24, 15, 16] After iteration 4, smallest number is 14 and it's index is 3 Array is [3, 9, 13, 14, 19, 24, 15, 16] After iteration 5, smallest number is 15 and it's index is 6 Array is [3, 9, 13, 14, 15, 24, 19, 16] After iteration 6, smallest number is 16 and it's index is 7 Array is [3, 9, 13, 14, 15, 16, 19, 24] After iteration 7, smallest number is 19 and it's index is 6 Array is [3, 9, 13, 14, 15, 16, 19, 24]
QUESTION: //Sort the array arr[] for (int i = 0; i < arr.length - 1; i++)...
Question 3 QUESTION //Sort the array arr[] for (int i = 0; i< arr.length - 1; i++) { for (int j = 1; i < arr.length - i; j++) { if (array[i-1] > array[i]) { // swap (j-1, ) }//if }//for i }//for i In the array= 19 7 23 12 4 8 17 158, after the completion of the outer iteration #4 , the array becomes = Answer
[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 -...
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...
int arr[] = {1,4, 1, 0); for (int i=0; i < 4; ++i) cout<<arr[i]*2; 0140 1014 1410 (space in between each number) 1410 None of the above void square(int &n){n= n*n;} int arr[] = {1, 2, 3}; int number = 4; Which of the following function calls are acceptable? square(1); square(arr[number]); square(number); square(2);
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,...
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)...
I'm trying to do an insertion sort in which i sort the characters of a string, what do i replace inputString.charAt(j) with? note: //arr[j] = arr[j-1] is an example that my professor used for an array. (just a reminder for myself) Written in Java lang public static String sort(String inputString) if (inputS tring null) t //insertion sortsort characters for(int i = 0; i inputstring.length(); i++) int index - inputString.charAt(i); int j- i; while( i> 0 && inputString.charAt (i-1) > index)...
Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1; R++ arr[k]-arr[k+1]; What are the contents of arr as a result of executing the code segment? a. {1, 2, 3, 5, 6, 7, 8, 8) b. {2, 2, 4, 5, 6, 7, 8, 8} C. {2, 4, 6, 5, 6, 7, 8,8} d. {4, 2, 4, 4, 6, 7, 8, 8) e. {6, 6, 4, 5, 6, 7, 8, 8} int) arr={7, 2.5, 3.0,...
the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...
what is the output of the following code segment? C++ g. int arr[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) arr[i][j] =i*4 + j; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) cout << arr[i][j] << " "; h. int next(int & x) { x= x + 1; return (x + 1); int main() { int y = 10;...