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 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...
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
(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...
Solve the following Double Linked List sort: use int. array = {8, 3, 12, 9, 6,...
Solve the following Double Linked List sort: use int. array = {8, 3, 12, 9, 6, 2} and provide visualization development to the solution.
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.
Suppose grades = [9, 7, 7, 10, 3, 9, 6, 6, 2] Write in Python An...
Suppose grades = [9, 7, 7, 10, 3, 9, 6, 6, 2] Write in Python An expression that evaluates to the number of 7 grades A statement that changes the last grade to 4 An expression that evaluates to the maximum grade A statement that sorts the list grades An expression that evaluates to the average grade
Sort a string array by frequency given an array of string write a function that will...
Sort a string array by frequency given an array of string write a function that will return an array that is sorted by frequency example {"hello","hola","hello","hello","ciao","hola","hola","hola"} returned array should be {"hola","hello","ciao"}
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.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT