Question

Selection Sort, which works by finding the smallest value in the unsorted part of the collection,...

Selection Sort, which works by finding the smallest value in the unsorted part of the collection, and exchanging it with the next unsorted value until the collection is sorted:

int selectionArray = {10, 23, 95, 48, 8};

Using the following format WITH NO SPACES in the entire line, type in what the array looks like for at the end of each pass.

[        ,         ,         ,         ,         ]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Answer:
--------
[8,23,95,48,10]
[8,10,95,48,23]
[8,10,23,48,95]
[8,10,23,48,95]

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

Iteration: 2
   > Replace element 23 with minimum number of remaining list [23, 95, 48, 10]
   > Minimum element found is 10. so, swap it with element at index 1 which is 23
   > List after iteration 2 is [8, 10, 95, 48, 23]

Iteration: 3
   > Replace element 95 with minimum number of remaining list [95, 48, 23]
   > Minimum element found is 23. so, swap it with element at index 2 which is 95
   > List after iteration 3 is [8, 10, 23, 48, 95]

Iteration: 4
   > Replace element 48 with minimum number of remaining list [48, 95]
   > Minimum element found is 48. so, swap it with element at index 3 which is 48
   > List after iteration 4 is [8, 10, 23, 48, 95]

Sorted list is [8, 10, 23, 48, 95]
Add a comment
Know the answer?
Add Answer to:
Selection Sort, which works by finding the smallest value in the unsorted part of the collection,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Selection Sort is a common algorithm to sort the elements of an array. First, it scans...

    Selection Sort is a common algorithm to sort the elements of an array. First, it scans the elements of the array to find the smallest value and places it at index 0, thus creating a sorted “subarray” of size 1 that contains the smallest value. Then it scans the remaining unsorted values for the new smallest value and places it at index 1, creating a sorted subarray of size 2 that contains the 2 smallest values. It continues in this...

  • //CODE 16-02.cpp //Demonstrates a template function that implements //a generic version of the selection sort algorithm....

    //CODE 16-02.cpp //Demonstrates a template function that implements //a generic version of the selection sort algorithm. #include <iostream> using std::cout; using std::endl; template<class T> void sort(T a[], int numberUsed); //Precondition: numberUsed <= declared size of the array a. //The array elements a[0] through a[numberUsed - 1] have values. //The assignment and < operator work for values of type T. //Postcondition: The values of a[0] through a[numberUsed - 1] have //been rearranged so that a[0] <= a[1] <=... <= a[numberUsed -...

  • Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers...

    Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. USE THIS STUCTURE struct nodeQ{                            node *front;                            node *rear;               };               nodeQ que[10]; enqueue(que[i],data); EXAMPLE: Original, unsorted list: [170, 45, 75, 90, 2, 802, 24, 66] 1ST PASS:...

  • 1. The bubble sort: a. Finds the smallest value and exchanges it with the first value,...

    1. The bubble sort: a. Finds the smallest value and exchanges it with the first value, then continues with the second value, third value, etc. b. Is a system of comparisons and exchanges of adjacent elements to move the largest to the bottom of the selected group of values. c. Is a system of comparisons and exchanges of elements that are non-adjacent. The gap is halved at each pass. d. None of the above. For the following array answer Q2...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • Java, Please implement the way the interface specifies. Part A:Radix Sort Implement a radix sort as...

    Java, Please implement the way the interface specifies. Part A:Radix Sort Implement a radix sort as described in the last section of Chapter 7 in your text. It should handle variable amounts of data and variable numbers of digits in the key values. Use testing to ensure radix sort works for at least three examples of different input sizes and various max digit length. I need to implement the radix sort using the below java interface. /** * <h1><LeastSignificantDigit Radix...

  • I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that...

    I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...

  • I want to compare the runtimes and swap operations times among quick Sort, selection Sort and...

    I want to compare the runtimes and swap operations times among quick Sort, selection Sort and shell Sort here is my code: But when I create a 1000,000 size array, I can't get the result of the operations times and runtime. what's wrong with my code? and I also want to copy the array. Because I want to use same array for three sort. And for the shell Sort, I haven't learn it in my class. Can anyone help me...

  • Here is the recursion tree for the above: I need to know the formula that counts...

    Here is the recursion tree for the above: I need to know the formula that counts the nodes in that recursion tree. An example: the recursion tree for a selection sort with an array of 4 in the worst case scenario looks like this: That is the type of solution I am looking for. Please determine the formula to count the number of nodes in the recursion tree for the insertion sort with an array size of 5 (n=5) where...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT