Question

In: Computer Science

Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Selection sort and shell sort....

Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Selection sort and shell sort. Write the algorithms. show work. please

Solutions

Expert Solution

Algorithm:
-----------
begin SelectionSort(list)
   for i from 0 to length of list - 1
      minIndex = i
      for j from i+1 to length of list - 1
        if list[j] < list[minIndex]
            minIndex = j;
        end if
      end for
      swap list[i] and list[minIndex]
   end for
   return list
end SelectionSort

Selection Sort tracing:
-----------------------
Selection sort
Original list is [33, 77, 22, 11, 34, 21, 88, 90, 42]
Iteration: 1
   > Replace element 33 with minimum number of remaining list [33, 77, 22, 11, 34, 21, 88, 90, 42]
   > Minimum element found is 11. so, swap it with element at index 0 which is 33
   > List after iteration 1 is [11, 77, 22, 33, 34, 21, 88, 90, 42]

Iteration: 2
   > Replace element 77 with minimum number of remaining list [77, 22, 33, 34, 21, 88, 90, 42]
   > Minimum element found is 21. so, swap it with element at index 1 which is 77
   > List after iteration 2 is [11, 21, 22, 33, 34, 77, 88, 90, 42]

Iteration: 3
   > Replace element 22 with minimum number of remaining list [22, 33, 34, 77, 88, 90, 42]
   > Minimum element found is 22. so, swap it with element at index 2 which is 22
   > List after iteration 3 is [11, 21, 22, 33, 34, 77, 88, 90, 42]

Iteration: 4
   > Replace element 33 with minimum number of remaining list [33, 34, 77, 88, 90, 42]
   > Minimum element found is 33. so, swap it with element at index 3 which is 33
   > List after iteration 4 is [11, 21, 22, 33, 34, 77, 88, 90, 42]

Iteration: 5
   > Replace element 34 with minimum number of remaining list [34, 77, 88, 90, 42]
   > Minimum element found is 34. so, swap it with element at index 4 which is 34
   > List after iteration 5 is [11, 21, 22, 33, 34, 77, 88, 90, 42]

Iteration: 6
   > Replace element 77 with minimum number of remaining list [77, 88, 90, 42]
   > Minimum element found is 42. so, swap it with element at index 5 which is 77
   > List after iteration 6 is [11, 21, 22, 33, 34, 42, 88, 90, 77]

Iteration: 7
   > Replace element 88 with minimum number of remaining list [88, 90, 77]
   > Minimum element found is 77. so, swap it with element at index 6 which is 88
   > List after iteration 7 is [11, 21, 22, 33, 34, 42, 77, 90, 88]

Iteration: 8
   > Replace element 90 with minimum number of remaining list [90, 88]
   > Minimum element found is 88. so, swap it with element at index 7 which is 90
   > List after iteration 8 is [11, 21, 22, 33, 34, 42, 77, 88, 90]

Sorted list is [11, 21, 22, 33, 34, 42, 77, 88, 90]

Related Solutions

Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Quick sort. Write the algorithm....
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Quick sort. Write the algorithm. show work
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Bubble sort, show work. Write...
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Bubble sort, show work. Write the algorithm.
selection sort for 12, 2, 3, 21, 11, 10,8
selection sort for 12, 2, 3, 21, 11, 10,8
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge...
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge sort, Radix sort, Bucket sort, and Counting sort.
Given the following data set 11 20 33 45 52 30 27 21 38 42 28...
Given the following data set 11 20 33 45 52 30 27 21 38 42 28 25 79 60 14 35 100 23 88 58 A. Find the quartiles B. Determine if there are any outliers C. Draw a box plot (exclude outliers but plot them as well).
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the...
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the process step-by-step, and find the time complexity in Big-O notation for each method. For sorting, use ascending order. 49, 7, 60, 44, 18, 105
I have this program, it sorts a file using shell sort and quick sort then prints...
I have this program, it sorts a file using shell sort and quick sort then prints amount of comparisons and swaps. I need to add the insertion algorithm. Here is the code. The language is Java. import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class Sort {    public static int numOfComps = 0,numOfSwaps = 0;     public static void main(String[] args)    {         try{        Scanner scanner = new Scanner(new File("a.txt"));//your text file here          ...
I have this program, it sorts a file using shell sort and quick sort then prints...
I have this program, it sorts a file using shell sort and quick sort then prints amount of comparisons and swaps. I need to add the bubble sort algorithm. Here is the code. The language is Java. import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class Sort {    public static int numOfComps = 0,numOfSwaps = 0;     public static void main(String[] args)    {         try{        Scanner scanner = new Scanner(new File("a.txt"));//your text file here       ...
Simulate the working operation of Insertion Sort for the array: [ 28, 13, 22, 7, 34,...
Simulate the working operation of Insertion Sort for the array: [ 28, 13, 22, 7, 34, 2, 15, 18 ]. Show your work at each step by writing the status of the array after every insertion.
Import a data set (txt file) then do the sorting algorithm using quick sort, shell sort,...
Import a data set (txt file) then do the sorting algorithm using quick sort, shell sort, and selection sort. It must show how long it took and how many movements occurred. Please write codes in C++ Here's data set (should be stored in txt file) 7426 4524 4737 9436 3997 2757 6288 5414 9590 5968 6638 3199 9514 1541 9866 2144 6731 911 2171 6135 6437 912 9417 2662 6606 6349 707 2890 5386 9718 3492 5068 9674 8578 8323...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT