Question

In: Computer Science

After three passes through the outer loop of a sorting algorithm, an array changes from 43...

After three passes through the outer loop of a sorting algorithm, an array changes from

43 16 48 37 81 54 71 29

to

16 29 37 48 81 54 71 43

What sorting algorithm is being used to sort the array?

A.

Selection sort

B.

Bubble sort

C.

Insertion sort

Solutions

Expert Solution

A) Selection sort


Original list is [43, 16, 48, 37, 81, 54, 71, 29]
Iteration: 1
   > Replace element 43 with minimum number of remaining list [43, 16, 48, 37, 81, 54, 71, 29]
   > Minimum element found is 16. so, swap it with element at index 0 which is 43
   > List after iteration 1 is [16, 43, 48, 37, 81, 54, 71, 29]

Iteration: 2
   > Replace element 43 with minimum number of remaining list [43, 48, 37, 81, 54, 71, 29]
   > Minimum element found is 29. so, swap it with element at index 1 which is 43
   > List after iteration 2 is [16, 29, 48, 37, 81, 54, 71, 43]

Iteration: 3
   > Replace element 48 with minimum number of remaining list [48, 37, 81, 54, 71, 43]
   > Minimum element found is 37. so, swap it with element at index 2 which is 48
   > List after iteration 3 is [16, 29, 37, 48, 81, 54, 71, 43]



Related Solutions

Following is the algorithm of Quicksort for sorting an array of integers in ascending order. Partition(numbers,...
Following is the algorithm of Quicksort for sorting an array of integers in ascending order. Partition(numbers, lowIndex, highIndex) {    midpoint = lowIndex + (highIndex - lowIndex) / 2    pivot = numbers[midpoint]    done = false    while (!done) {       while (numbers[lowIndex] < pivot)          lowIndex++       while (pivot < numbers[highIndex])          highIndex--       if (lowIndex >= highIndex) {          done = true       }       else {          temp = numbers[lowIndex]          numbers[lowIndex] = numbers[highIndex]          numbers[highIndex] = temp                 lowIndex++          highIndex--       }    }    return highIndex } Quicksort(numbers, lowIndex, highIndex) {    if (lowIndex...
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 +...
How could the fluid that passes through, the proximal convoluted tubule, the loop of Henle, the...
How could the fluid that passes through, the proximal convoluted tubule, the loop of Henle, the distal convoluted tubule and the collecting conductors be?
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through...
. Consider the following sorting procedure. This procedure uses nested loops to make several passes through the array. Each pass compares successive pairs of elements. If a pair is in increasing order (or the values are equal), the sorting procedure leaves the values as they are. If a pair is in decreasing order, the sorting procedure swaps their values in the array.  The first pass compares the first two elements of the array and swaps their values if necessary....
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through...
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through the array elements and accumulate the sum of ASCII value of each character in element and return the total. For example: function([‘A’, ‘bc’, 12]); // returns 361 which is the sum of 65 + 98 + 99 + 49 + 50 Use of any built in string functions or built in array functions is not allowed, Any help would be much appreciated
Light coming from an unpolarized source passes through three polarizers. They are in series. Their transmissions...
Light coming from an unpolarized source passes through three polarizers. They are in series. Their transmissions axes are at 1=40, 2=60, 3= 90. The final intensity is I. Another polarizer is places between the source and the first polarizer at angle of 90. New final intensity of the system is I'. What is the ratio of I'/I.
a) How does the magnetic flux through the loop changes as the magnet rotates. Is the...
a) How does the magnetic flux through the loop changes as the magnet rotates. Is the flux maximal when the magnet is horizontal or vertical on the screen? Why? b) How does changing the magnetic flux works to create an emf (potential difference) in the coil, which alternates over time (use the Faraday’s law equation)?
The 2.0-cm-diameter solenoid in the figure passes through the center of a 6.0-cm-diameter loop. The magnetic...
The 2.0-cm-diameter solenoid in the figure passes through the center of a 6.0-cm-diameter loop. The magnetic field inside the solenoid is 0.20 1. What is the magnetic flux through the loop when it is perpendicular to the solenoid? What is the magnetic flux through the loop when it is perpendicular to the solenoid? Express your answer using two significant figures. Magnetic Flux = ______ Wb 2. What is the magnetic flux through the loop when it is tilted at a...
list the structure and fluids that light passes through from the cornea to the retina?
list the structure and fluids that light passes through from the cornea to the retina?
A locomotive is accelerating at 1.6 m/s2 as it passes through a 30-m-wide crossing. After the...
A locomotive is accelerating at 1.6 m/s2 as it passes through a 30-m-wide crossing. After the locomotive leaves the crossing, how much time is required until its speed reaches 40?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT