.Use the selection sort to put the following list in order. (5 credits) (I’ve put the list in an array (boxes so you can see the distinct elements clearly.
You can just type the numbers across the page in answering.
Remember to show the sort marker as is done in your book.)
Show the list after each exchange that has an effect on the list ordering.
Unsorted list: 26 17 32 47 56 9 12 72 3 25
26 17 32 47 56 9 12 72 3 25 | <-- sort marker
Selection Sort: -
Selection sort is a popular sorting algorithm, which repeatedly finds the minimum element of an unsorted array and puts it at the beginning. During every iteration the sort algorithm moves the minimum value from the unsorted array part and moves it to the sorted array part
Suppose the unsorted array is 26, 17, 32, 47, 56, 9, 12, 72, 3, 25, of length 10, and indices 0 to 9
First iteration finds the minimum element from array [0:9] and places it at array [0]
Ie, 3, 26, 17, 32, 47, 56, 9, 12, 72, 25
Second iteration finds the minimum element from array [1:9] and places it at array [1]
Ie, 3, 9, 26, 17, 32, 47, 56, 12, 72, 25
Third iteration finds the minimum element from array [2:9] and places it at array [2]
Ie, 3, 9, 12, 26, 17, 32, 47, 56, 72, 25
This goes on and finally a sorted array is created 3,9,12,17,25,26,32,47,56,72
Python code for selection sort: -
def selection_sort(arr):
N=len(arr)
for start in range(N):
min_pos=start
for j in range(start, N):
if arr[j] < arr[min_pos]:
min_pos=j
arr[start],arr[min_pos] =arr[min_pos],arr[start]
test_arr=[26, 17, 32, 47, 56, 9, 12, 72, 3, 25]
selection_sort(test_arr)
print(test_arr)
.Use the selection sort to put the following list in order. (5 credits) (I’ve put the...
Show the execution of the selection sort algorithm on the following array. Hint: The yellow or shaded squares should be the remaining unsorted values. Pass # 0 1 2 3 4 5 6 7 0 16 11 21 32 41 20 3 9 1 2 3 4 5 6 7 Show the execution of the insertion sort algorithm on the following array. Hint: The yellow or shaded squares should be the remaining unsorted values. Pass # 0 1 2 3...
Sort the following array of integer using selection and insertion sort algorithms. Notdoing the program . Show it step by step. { 20 12 8 4 13 9 26 18 25 14}.
Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...
How to write this in c++? 1. Sort the following list using the selection sort algorithm as discussed in this chapter. Show the list after each iteration of the outer for loop. 36, 55, 17, 35, 63, 85, 12, 48, 3, 66 (10 points)
2. Suggest a structured plan (algorithm) for the bubble sort and selection sort, and perform running time analysis for both best and worst case. 3. Consider the age data of 12 children who are supposed to undergo for vaccination in ascending order of their age. Suggest and apply a sorting technique which can efficiently handle this data. Show all the intermediate steps clearly. Child ID 01 02 03 04 05 06 07 08 09 10 11 12 2. Age 1...
Use Quick sort to sort the following list. Show the actions step by step 123, 34, 189, 56, 150, 12, 9, 240
Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...
Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a = [ [93, 80, 99, 72, 86, 84, 85, 41, 69, 31], [15, 37, 58, 59, 98, 40, 63, 84, 87, 15], [48, 50, 43, 68, 69, 43, 46, 83, 11, 50], [52, 49, 87, 77, 39, 21, 84, 13, 27, 82], [64, 49, 12, 42, 24, 54, 43, 69, 62, 44], [54, 90, 67, 43, 72, 17, 22, 83, 28, 68], [18, 12, 10,...
C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential search of a list assumes that the list elements are sorted in ascending order. b. A binary search of a list assumes that the list is sorted. 2. Consider the following list: 63 45 32 98 46 57 28 100 Using a sequential search, how many comparisons are required to determine whether the following items are in the list or not? (Recall that comparisons...
1. (5 marks) Perform a selection sort on the list 23, 59, 34, 13, 31, 10. Show the list after each exchange that has an effect on the list ordering. 2. (5 marks) Explain why the bubble sort algorithm does Ө(n2) comparisons on an n-element list. The bubble-sort algorithm is shown just after question 10 on p. 141. 3. (5 marks) Write the resulting data list, give the ending value of legit, and find the exact number of copies done by the converging...