Question

In: Computer Science

Suppose you are given the following array X = [7, 9, 1, 6] Sort the array...

  1. Suppose you are given the following array

X = [7, 9, 1, 6]

Sort the array in ascending order using the selction sort algorithm.

Write the state of the array after each pass.

Pass1:

Pass2:

Pass3:

  1. Suppose you are given the following array

X = [7, 9, 1, 6]

Sort the array in ascending order using the selction sort algorithm.

Write the state of the array after each pass.

Pass1:

Pass2:

Pass3:

Solutions

Expert Solution

Pass1:  [1, 9, 7, 6]
Pass2:  [1, 6, 7, 9]
Pass3:  [1, 6, 7, 9]

Explanation:
-------------
Selection sort
Original list is [7, 9, 1, 6]
Iteration: 1
   > Replace element 7 with minimum number of remaining list [7, 9, 1, 6]
   > Minimum element found is 1. so, swap it with element at index 0 which is 7
   > List after iteration 1 is [1, 9, 7, 6]

Iteration: 2
   > Replace element 9 with minimum number of remaining list [9, 7, 6]
   > Minimum element found is 6. so, swap it with element at index 1 which is 9
   > List after iteration 2 is [1, 6, 7, 9]

Iteration: 3
   > Replace element 7 with minimum number of remaining list [7, 9]
   > Minimum element found is 7. so, swap it with element at index 2 which is 7
   > List after iteration 3 is [1, 6, 7, 9]

Sorted list is [1, 6, 7, 9]



Related Solutions

Given the matrix 7 7 -4 12 -5 A = 9 10 2 6 13 8 11 15 4 1 3. a. Sort each column and store the result in an array B.
Given the matrix a. Sort each column and store the result in an array B.b. Sort each row and store the result in an array C.c. Add each column and store the result in an array D.d. Add each row and store the result in an array E.  
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
//   Given an array of size 9, with the values of 1-9, determine if the array...
//   Given an array of size 9, with the values of 1-9, determine if the array //   is valid or not. //   Display a message stating the row is VALId, or state its INVALID and what //   was the index number that determined the data invalid. // //   Use this java code as a start of your code. //   Test the array data by changing the values. //============================================================================= import java.util.*;    public class Soduko_ValidateRow    { public static void main(String...
(a) Suppose you are given the following x, y data pairs x 1 3 6 y...
(a) Suppose you are given the following x, y data pairs x 1 3 6 y 5 5 8 Find the least-squares equation for these data. (Use 3 decimal places.) y hat = + x (b) Now suppose you are given these x, y data pairs. x 5 5 8 y 1 3 6 Find the least-squares equation for these data. (Use 3 decimal places.) y hat = + x (c) In the data for parts (a) and (b), did...
Create a quick and merge sort algorithm that sorts 6 9 8 12 3 1 7...
Create a quick and merge sort algorithm that sorts 6 9 8 12 3 1 7 In java please.
Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
Given the following data: x 2 8 5 12 9 y 6 11 7 14 10...
Given the following data: x 2 8 5 12 9 y 6 11 7 14 10 a) draw/graph a scatter plot. b) by hand, find the correlation coefficient r. c) by hand, find b0 and b1. d) write the regression equation.
6. Given the following array of characters: REALITYSHOWShow how this array will be sorted with the...
6. Given the following array of characters: REALITYSHOWShow how this array will be sorted with the help of : (a) insertion sort; (b) selection sort; (c) bubble sort with swaps counting; (d) bubble sort without swaps counting subject design and analysis of algorithms answer should be like eg p u r p l e p r u p l e
(a) Suppose you are given the following (x, y) data pairs. x 2 3 6 y...
(a) Suppose you are given the following (x, y) data pairs. x 2 3 6 y 4 3 9 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ =  +  x (b) Now suppose you are given these (x, y) data pairs. x 4 3 9 y 2 3 6 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ =  +  x (c) In the data for parts (a) and (b), did...
(a) Suppose you are given the following (x, y) data pairs. x 2 3 6 y...
(a) Suppose you are given the following (x, y) data pairs. x 2 3 6 y 4 3 9 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ = (b) Now suppose you are given these (x, y) data pairs. x 4 3 9 y 2 3 6 Find the least-squares equation for these data (rounded to three digits after the decimal). ŷ = d) Solve your answer from part (a) for x (rounded...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT