Question

In: Computer Science

Show the contents of the array after the fourth iteration of selectionSort Your answer should be...

Show the contents of the array after the fourth iteration of selectionSort

Your answer should be 4 lines
The array values horizontally for iteration 1
The array values horizontally for iteration 2
The array values horizontally for iteration 3
The array values horizontally for iteration 4

Solutions

Expert Solution

class SelectionSort {
        void sort(int arr[]) {
                int n = arr.length;

                // One by one move boundary of unsorted subarray
                for (int i = 0; i < n - 1; i++) {
                        // Find the minimum element in unsorted array
                        int min_idx = i;
                        for (int j = i + 1; j < n; j++)
                                if (arr[j] < arr[min_idx])
                                        min_idx = j;

                        // Swap the found minimum element with the first
                        // element
                        int temp = arr[min_idx];
                        arr[min_idx] = arr[i];
                        arr[i] = temp;
                        printArray(arr,i+1);
                }
        }

        // Prints the array
        void printArray(int arr[],int itr) {
                int n = arr.length;
                System.out.print(" iteration "+itr+": ");
                for (int i = 0; i < n; ++i)
                        System.out.print(arr[i] + " ");
                System.out.println();
        }

        // Driver code to test above
        public static void main(String args[]) {
                SelectionSort ob = new SelectionSort();
                int arr[] = {44,36,46,32,38,52,30,26};
                ob.sort(arr);
        }
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

What are the contents of the array after the for-loop in the following code?
(IN C)What are the contents of the array after the for-loop in the following code?int array[ SIZE ][ SIZE ] = { { 4, 5, 6, 7, 8 },{ 1, 2, 3, 4, 5 },{ 3, 6, 7, 8, 9 },{ 2, 3, 4, 5, 6 },{ 5, 6, 7, 8, 9 } };int i;int *ptr = array[ 0 ];for( i = 0; i < SIZE * SIZE; i++ ) {if( i % SIZE < 2 ) {*( ptr +...
(Data structure) Show the contents of the array below, once the “pivot” element is placed at...
(Data structure) Show the contents of the array below, once the “pivot” element is placed at its appropriate location after each call of the “Partition” algorithm, in the process of running Quick-Sort on said array. Arrange the data in descending order (from largest to smallest value). Always select the first element of the partition as “pivot” Apply sorting on the following data set s,       f,       p,      a,      g,      e,       v,      q,      i,        c
1) What's the contents of array vals after the following code is executed? int[] vals =...
1) What's the contents of array vals after the following code is executed? int[] vals = {6, 1, 4, 5, 1}; int size = vals.length; for(int i = 0; i < size; i++) vals[i] = vals[i] * i; q) [ 6, 1, 4, 5, 1 ] b)[ 0, 1, 2, 3, 4] c)[0, 1, 8, 15, 4] d)[6, 2, 12, 20, 5] 2) Consider function foo defined below: static int[] foo(int vals[]) { int result[] = new int[vals.length - 1];...
Ex 1. Show the contents of the array of integers 5 7 4 9 8 5...
Ex 1. Show the contents of the array of integers 5 7 4 9 8 5 6 3 each time a selection sort changes it while sorting the array into ascending order. Initial array:   5 7 4 9 8 5 6 3 ANSWER (Hint there are 8 lines, Show Array after each selection and swap):
Understanding Assembly Language. For each problem, show the contents or setting of the requested items after...
Understanding Assembly Language. For each problem, show the contents or setting of the requested items after executing the instructions. mov eax, 0FFFFFBFDh ; i.e., -1027 mov ebx, -16        ; i.e., FFFFFFF0h mov edx, 0 idiv bl Show the hexadecimal digits in eax:_______________ Show the hexadecimal digits in edx:_______________ mov eax, 0FFFFFBFDh ; i.e., -1027 mov ebx, -16        ; i.e., FFFFFFF0h mov edx, 0 cwd idiv bx Show the hexadecimal digits in eax:_______________ Show the hexadecimal digits in edx:_______________ mov eax,...
(Please justify your answer) A rare mutation generates a fourth blood group, C, where they are...
(Please justify your answer) A rare mutation generates a fourth blood group, C, where they are missing one additional carbohydrate from the glycoprotein, i.e. type I with one more sugar missing. What ABO blood groups could donate to this individual?
For the given array, simulate the working operation of Bubble Sort. Show your work at each...
For the given array, simulate the working operation of Bubble Sort. Show your work at each step. Make sure to show the status of the array after every swap. [ 28, 13, 22, 7, 34, 2 ]
"The Borderfree Option" case is your fourth case write-up option. You will answer the following questions...
"The Borderfree Option" case is your fourth case write-up option. You will answer the following questions listed at the end of the case 1) Explain what Borderfree does. Why would an SME find that appealing? 2) What mix of ownership, location, and internalization advantages would encourage a company to hire Borderfree? 3) Borderfree's clients expect it to be knowledgeable about the key markets in which the operate and to be able to advise on how too prioritize, budget, and compete....
Answer should show an understanding of the species concepts and a defensible use of evidence. •...
Answer should show an understanding of the species concepts and a defensible use of evidence. • Correct definition of species concept • Selection of evidence that is relevant to the species concept and good explanation of how the evidence is used. • Clear description of additional evidence that is relevant to the species concept Two morphs of the marine snail Littorina saxatilis have been identified on rocky intertidal shores in Galacia, Spain. Johannesson et al (1995) made the following observations...
Answer the following questions. Show all work leading to your answer. On a network with an...
Answer the following questions. Show all work leading to your answer. On a network with an IP address of 140.133.28.72 and a subnet mask of 255.248.0.0, what is the network ID? You have decided to create 254 subnets on your Class B network. What subnet mask will you use to accomplish this? What is the maximum number of hosts you can assign to any single subnet? Your workstation's IP address is 10.35.88.12, and your supervisor's workstation's IP address is 10.35.91.4....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT