Question

Use the selection sort to sort 6, 2, 3, 1, 5, 4, showing the lists obtained...

Use the selection sort to sort 6, 2, 3, 1, 5, 4, showing the lists obtained at each step.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

List : 6, 2, 3, 1, 5, 4

Let us consider the list to start at index 0 and end at index 5

Step 1: 1, 2, 3, 6, 5, 4

(Find the minimum element from index 0 to 5 and place it at the beginning)

Step 2: 1, 2, 3, 6, 5, 4

(Find the minimum element from index 1 to 5 and place it at index 1.Here the element is already in position)

Step 3: 1, 2, 3, 6, 5, 4

(Find the minimum element from index 2 to 5 and place it at index 2.Here the element is already in podition)

Step 4: 1, 2, 3, 4, 5, 6

(Find the minimum element from index 3 to 5 and place it at index 3)

Step 5: 1, 2, 3, 4, 5, 6

(Find the minimum element from index 4 to 5 and place it at index 4)

Add a comment
Know the answer?
Add Answer to:
Use the selection sort to sort 6, 2, 3, 1, 5, 4, showing the lists obtained...
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
  • a) Use the bubble sort to sort g, j, o, n, d, f showing the lists...

    a) Use the bubble sort to sort g, j, o, n, d, f showing the lists obtained at each step. b) Show that the function f(n) = (n + 3)(5n – 1) + 13 is O(n?).

  • [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9,...

    [5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9, 4, 3). Assuming we call the following function using statement selection sort (int array, 7); Please fill the table to show the changes of the array int_array after each iteration. The first column is filled. void selection_sort (int list[], int list_size) for (int i = 0; i < list size - 1; 1++) int current min = list[1]; int current_min_index-i for (int j -...

  • Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and...

    Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...

  • 1. Given a set of numbers: A = {1, 3, 5, 2, 8, 7, 9, 4...

    1. Given a set of numbers: A = {1, 3, 5, 2, 8, 7, 9, 4 }. Add each digit of your N-Number (e.g. N0 0 3 2 2 0 1 8) to each element of A separately to get your own final array B. ( e.g. B={1,3,8,4,10,7,10,12} = {B1,B2,B3,B4,B5,B6,B7,B8}. ) a) Your set B = ? b) Use merge-sort to sort the array B. Show each step. c) How many “comparisons” for each algorithm above? 2. Use binary-search for...

  • Sort the list of numbers: 35, 12, 6, 23, 18 using Selection sort. Work through each...

    Sort the list of numbers: 35, 12, 6, 23, 18 using Selection sort. Work through each step of the algorithm. The algorithm for selection sort is as follows: i. Find the smallest item in a list. ii. Swap this value with the value currently at the front of the list. iii. Repeat Steps 1 and 2 with the current size of the list minus one (list size = list size-1)

  • Question 5 (10 Points) Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection-Sort...

    Question 5 (10 Points) Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection-Sort segments the list into sorted and unsorted elements. The algorithm continues to remove the smallest element of the unsorted list and adds it to the sorted segment. Implement the algorithm that accepts an unsorted list and returns a sorted one - in ascending order. 5 3 8 Initial List 4 6 18 4 6 Minimum Swaps Position: Sorted List Length 1 Minimum Swaps Position:...

  • Sort 3, 5, 2, 1, 5, 9, 4, 7, 6, 3 using Quicksort with median-of-three partitioning....

    Sort 3, 5, 2, 1, 5, 9, 4, 7, 6, 3 using Quicksort with median-of-three partitioning. Assume a cutoff of 3, i.e. once a partition size reaches 3, the elements are sorted by explicit comparison. You do not have to show each step of the i and j pointers, but clearly indicate which elements are swapped in each step. Assume that the three candidate elements are not pre-sorted when selecting the pivot, but that the pivot is moved to the...

  • Question 4 1 pts Comparing the amount of memory required by selection sort and insertion sort,...

    Question 4 1 pts Comparing the amount of memory required by selection sort and insertion sort, what can one say? Insertion sort requires more additional memory than selection sort Selection sort requires more additional memory than insertion sort O Both methods require about as much additional memory as the data they are sorting Neither method requires additional memory None of the above Question 5 1 pts The type of the reference, not the type of the object, is use to...

  • DATA STRUCTURE 1) Sort 3, 4, 5, 6,1, 9, 2, 5, 6 using insertion sort.

    DATA STRUCTURE 1) Sort 3, 4, 5, 6,1, 9, 2, 5, 6 using insertion sort.

  • Suppose that we've completed the split (divide) step of the merge sort, and produced 6 single...

    Suppose that we've completed the split (divide) step of the merge sort, and produced 6 single item sub-lists. [1] [2] [3] [4] [5] [6] What will be the values of the 2-item sub-lists in the merge step?

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